This article describes the PHP to achieve the calculation of Baidu map coordinates the distance between the method. Share to everyone for your reference, specific as follows:
The following is the code on the Web, you need to make some changes when you use it
The first function is to obtain the range, the parameter is the latitude longitude radius
The second function is to compute the coordinate distance
<?php define (' PI ', 3.1415926535898);
Define (' Earth_radius ', 6378.137);
The range of calculations can be done by searching user function GetRange ($lat, $lon, $raidus) {//computed latitude $degree = (24901 * 1609)/360.0;
$dpmLat = 1/$degree;
$radiusLat = $dpmLat * $raidus; $minLat = $lat-$radiusLat; Get the minimum latitude $maxLat = $lat + $radiusLat;
The maximum latitude/longitude is computed $mpdLng = $degree * cos ($lat * (pi/180));
$dpmLng = 1/$mpdLng;
$radiusLng = $dpmLng * $raidus; $minLng = $lon-$radiusLng; To obtain the minimum longitude $maxLng = $lon + $radiusLng;
Get maximum longitude/range $range = Array (' Minlat ' => $minLat, ' Maxlat ' => $maxLat, ' Minlon ' => $minLng,
' Maxlon ' => $maxLng);
return $range;
//Get Distance function getdistance between 2 points ($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;
}
For more information on PHP related content readers can view the site topics: "PHP array" Operation Techniques Encyclopedia, "PHP Mathematical Calculation Skills Summary", "PHP Regular Expression Usage Summary", "Php+ajax Tips and Application Summary", "PHP operation and operator Usage Summary", " PHP Network Programming Skills Summary, "Introduction to PHP Basic Grammar", "PHP date and Time usage summary", "PHP object-oriented Programming Introductory Course", "PHP string (String) Usage Summary", "Php+mysql database Operation Tutorial" and " A summary of common PHP database operations tips
I hope this article will help you with the PHP program design.