samedi 5 décembre 2020

How to get Data by distance according to google map distance in laravel

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();



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire