google maps - PHP - calculate latitude & longitude which is nearer than 50 km -
i have these data:
latitude: 50.223137
longitude: 18.679558
and create special function in php able calculate minimum lat & long , maximum lat & long nearer 50 km. 4 parameters , use these parameters in simple sql query: select * table lat >= [min_lat] , lng >= [min_lng] , lat <= [max_lat] , lng <= [max_lng];
i know, can using 1 sql query: latitude/longitude find nearest latitude/longitude - complex sql or complex calculation have 20.000.000 records in database , still grow up. have search in sql database other things want calculate based on php , search in sql in way: select * table lat >= [min_lat] , lng >= [min_lng] , lat <= [max_lat] , lng <= [max_lng];
because think - faster way.
i found function: https://www.geodatasource.com/developers/php , great want create function in other way - want declare argument: lat, lng , distance (for example: 50 km). 4 parameters - min_lat, min_lng, max_lat, max_lng.
anybody can me create function?
thanks.
you can use code ang give try. benchmarks.
<?php $lat = 50.223137; //latitude $lon = 18.679558; //longitude $distance = 50; //your distance in km $r = 6371; //constant earth radius. can add precision here if wish $maxlat = $lat + rad2deg($distance/$r); $minlat = $lat - rad2deg($distance/$r); $maxlon = $lon + rad2deg(asin($distance/$r) / cos(deg2rad($lat))); $minlon = $lon - rad2deg(asin($distance/$r) / cos(deg2rad($lat))); echo $maxlat, "<br>", $minlat, "<br>", $maxlon, "<br>", $minlon;
output:
50.672797802959 49.773476197041 19.382380506501 17.976735493499