/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     Hotspot::truncate();
     $places = Place::all();
     $clusters = $this->getClusters($places->all(), 1.5);
     $centroids = $this->getCentroids($clusters);
     $hotspots = array_map(function ($centroid) {
         $locality = $this->getLocalityForLatLon($centroid['latitude'], $centroid['longitude']);
         $categories = [];
         foreach ($centroid['places'] as $place) {
             foreach ($place->ranks as $rank) {
                 if (!isset($categories[$rank->category->name])) {
                     $categories[$rank->category->name] = 0;
                 }
                 $categories[$rank->category->name]++;
             }
         }
         arsort($categories);
         $categoryNames = array_keys($categories);
         return Hotspot::create(['name' => $locality, 'known_for' => implode(', ', $categoryNames), 'latitude' => $centroid['latitude'], 'longitude' => $centroid['longitude'], 'count' => $centroid['count']]);
     }, $centroids);
 }
Exemple #2
0
     if (!$city) {
         abort(400, 'City not supported.');
     }
     $radius = 1.5;
     $places = \App\Place::select(DB::raw("*, (6371 * acos( cos( radians({$lat}) ) * cos( radians( latitude ) ) * cos( radians( {$lon} ) - radians(longitude) ) + sin( radians({$lat}) ) * sin( radians(latitude) ) )) AS distance"))->having('distance', '<', $radius)->orderby('distance', 'asc')->with('ranks', 'ranks.category')->get();
     return response()->json($places);
 });
 Route::get('/hotspots', function () {
     $lat = \Illuminate\Support\Facades\Input::get('lat', -27.49611);
     $lon = \Illuminate\Support\Facades\Input::get('lon', 153.00207);
     $radius = 15;
     $hotspots = \App\Hotspot::select(DB::raw("*, (6371 * acos( cos( radians({$lat}) ) * cos( radians( latitude ) ) * cos( radians( {$lon} ) - radians(longitude) ) + sin( radians({$lat}) ) * sin( radians(latitude) ) )) AS distance"))->having('distance', '<', $radius)->orderby('distance', 'asc')->get();
     return response()->json($hotspots);
 });
 Route::get('/hotspots/{hotspotId}', function ($hotspotId) {
     $hotspot = \App\Hotspot::find($hotspotId);
     return response()->json($hotspot);
 });
 Route::get('/categories', function () {
     $lat = \Illuminate\Support\Facades\Input::get('lat', -27.49611);
     $lon = \Illuminate\Support\Facades\Input::get('lon', 153.00207);
     $radius = 50;
     // Get city for lat lon
     $city = \App\City::select(DB::raw("*, (6371 * acos( cos( radians({$lat}) ) * cos( radians( latitude ) ) * cos( radians( {$lon} ) - radians(longitude) ) + sin( radians({$lat}) ) * sin( radians(latitude) ) )) AS distance"))->having('distance', '<', $radius)->orderby('distance', 'asc')->first();
     if (!$city) {
         abort(400, 'City not supported.');
     }
     // get all the categories in the cities
     $categories = \App\Category::whereHas('ranks', function ($query) use($city) {
         $query->where('city_id', '=', $city->id);
     })->get();