mercredi 1 janvier 2020

Is there any way to find location with in radius in laravel

How can I find radious based Location based on one point latitude and longitude and given radius. Suppose, I have given 30 as Radius than it will find result of that particular given latitude and longitude with in the 30 radius. I have tried below code:

    $lat = '37.421998'; // latitude of centre of bounding circle in degrees
    $lon = '-122.084000'; // longitude of centre of bounding circle in degrees
    $rad = 30; // radius of bounding circle in kilometers

    $R = 6371;  // earth's mean radius, km

    // first-cut bounding box (in degrees)
    $maxLat = $lat + rad2deg($rad/$R);
    $minLat = $lat - rad2deg($rad/$R);
    $maxLon = $lon + rad2deg(asin($rad/$R) / cos(deg2rad($lat)));
    $minLon = $lon - rad2deg(asin($rad/$R) / cos(deg2rad($lat)));

   $results = DB::select('Select id, latitude, longitude, acos(sin(:lat)*sin(radians(latitude)) + cos(:lat)*cos(radians(latitude))*cos(radians(longitude)-(:lon))) * (:R) As D From ( Select id, latitude, longitude From jobs_master Where latitude Between (:minLat) And (:maxLat) And longitude Between (:minLon) And (:maxLon) ) As FirstCut Where acos(sin(:lat)*sin(radians(latitude)) + cos(:lat)*cos( radians(latitude))*cos(radians(longitude)-(:lon))) * :R < :rad ', ['maxLat' => $maxLat,'maxLon' => $maxLon, 'minLat' => $minLat,'minLon' => $minLon, 'lat' => $lat,'lon' => $lon,'R'=> $R,'rad'=>$rad]);

        dd(DB::getQueryLog());exit;
        print_r($results);exit;

Can any one help me.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Qi4G5T
via IFTTT

Aucun commentaire:

Enregistrer un commentaire