Define (' PI ', 3.1415926535898);d efine (' Earth_radius ', 6378.137);//calculation range, can do search user function GetRange ($lat, $lon, $raidus) {//calculate latitude $degree = (24901 * 1609)/360.0; $dpmLat = 1/$degree; $radiusLat = $dpmLat * $raidus; $minLat = $lat-$radiusLat; Get the minimum latitude $maxLat = $lat + $radiusLat; Get maximum latitude//calculate Longitude $mpdLng = $degree * cos ($lat * (pi/180)); $dpmLng = 1/$mpdLng; $radiusLng = $dpmLng * $raidus; $minLng = $lon-$radiusLng; Get the minimum longitude $maxLng = $lon + $radiusLng; Get the maximum longitude//Range $range = Array (' minlat ' = = $minLat, ' maxlat ' = $maxLat, ' minlon ' = $m INLNG, ' maxlon ' = $maxLng); return $range;} Get distance between 2 points function getdistance ($lat 1, $lng 1, $lat 2, $lng 2) {$radLat 1 = $lat 1 * (pi/180); $radLat 2 = $lat 2 * (pi/180); $a = $radLat 1-$radLat 2; $b = ($lng 1 * (pi/180))-($lng 2 * (pi/180)); $s = 2 * ASIN (sqrt (Pow (sin ($a/2), 2) + cos ($radLat 1) *cos ($radLat 2) *pow (sin ($b/2), 2))); $s = $s * Earth_radius; $s = round ($s * 10000)/10000; return $s; }
PHP calculates the distance between two points of coordinates