I have List ``provider``` .Their longitude and latitude are save in database. Now I want to fetch data order by that distance. One method is that I can use distance formula in my database query . But Problem is that formula displays straight line distance between two points but google map distance is clear.
Sometimes straight line distance could be greater than google driving distance and vice versa. SO My Querstion is is there any method i can make query according google map distance in my database .
Currently what I am doing is which is not working
$provider= Provider::query();
$provider = $provider->orderBy(DB::raw("3959 * acos( cos( radians({$request->input('latitude')}) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(-{$request->input('longitude')}) ) + sin( radians({$request->input('latitude')}) ) * sin(radians(latitude)) )"), 'DESC');
$provider = $provider->get();
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2VDVEC2
via IFTTT
Aucun commentaire:
Enregistrer un commentaire