I am trying to get a neraby store in Laravel 5.1 I have a geocoding parser that caluclate coorinate. But I have a problem with haversine formulas. Basically, I need to take neighboring stores from the Aziende (Stores) table, taking into account lat, the long category of e transmitted via the URL.
I am trying to use this code:
$dove = Input::get('dove');
$categoria_id = Input::get('id_categoria');
if (!empty($dove)) {
$response = \GoogleMaps::load('geocoding')->setParamByKey ('address', $dove)->get();
$response = json_decode($response, true);
$latitude = $response['results'][0]['geometry']['location']['lat'];
$longitude = $response['results'][0]['geometry']['location']['lng'];
$radius = '5';
$aziende = DB::table('aziende')
->select(
( 'lat * acos( cos( radians(50) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) )
+ sin( radians(37) ) * sin( radians( lat ) ) ) as distance') )->get();
} else {
$aziende = DB::table("aziende")->where('categoria', $categoria_id)->get();
}
?>
source
share