In this paper, we describe the method of calculating the distance between Baidu map coordinates by PHP. Share to everyone for your reference, as follows:
The following is the online code, the use of the time needed to make some changes
The first function is to get the range, the parameter is the latitude longitude radius
The second function is to calculate the coordinate distance
<?phpdefine (' PI ', 3.1415926535898);d efine (' Earth_radius ', 6378.137);//compute range, can do search user function GetRange ($lat, $lon, $raidus) {//Compute 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 ' = = $minLng, ' Maxlo n ' = $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;}
More about PHP related content readers can view the topic: "PHP array" operation Skills Daquan, "PHP Math Skills Summary", "PHP Regular Expression Usage Summary", "Php+ajax Tips and Applications Summary", "PHP operation and operator Usage Summary", " PHP Network Programming Skills Summary, PHP Basic Grammar Introductory tutorial, PHP date and Time usage summary, PHP Object-oriented Programming primer tutorial, PHP string Usage Summary, PHP+MYSQL Database Operations primer, and A summary of common PHP database operation techniques
I hope this article is helpful to you in PHP programming.
The above describes the PHP implementation of the calculation of Baidu map coordinates distance between the method, including Baidu map, the method of the content, I hope that the PHP tutorial interested friends have helped.