Php calculates the distance between the coordinates of Baidu Maps, and php coordinates. Php is used to calculate the distance between Baidu map coordinates. This article describes how php calculates the distance between Baidu map coordinates. For your reference, php coordinates are used to calculate the distance between Baidu map coordinates.
This article describes how php calculates the distance between Baidu map coordinates. We will share this with you for your reference. The details are as follows:
The following is the online code. some modifications are required when using the code.
The first function is to obtain the range. the parameter is the latitude longitude radius.
The second function is to calculate the coordinate distance.
<? Phpdefine ('pi ', 3.1415926535898); define ('Earth _ RADIUS', 6378.137); // You can search for the user function GetRange ($ lat, $ lon, $ raidus) {// latitude of calculation $ degree = (24901*1609)/360.0; $ dpmLat = 1/$ degree; $ radiusLat = $ dpmLat * $ raidus; $ minLat = $ lat-$ radiusLat; // obtain the minimum latitude. $ maxLat = $ lat + $ radiusLat; // obtain the maximum latitude // calculate the longitude $ mpdLng = $ degree * cos ($ lat * (PI/180); $ dpmLng = 1/$ mpdLng; $ radiusLng = $ dpmLng * $ raidus; $ minLng = $ lon-$ radiusLng; // obtain the minimum longitude $ maxLng = $ lon + $ radiusLng; // obtain the maximum longitude // range $ range = array ('minlat' => $ minLat, 'maxlat' => $ maxLat, 'minlon '=> $ minLng, 'maxlon '=> $ maxLng); return $ range;} // Obtain the distance between two points. function GetDistance ($ lat1, $ lng1, $ lat2, $ lng2) {$ radLat1 = $ lat1 * (PI/180); $ radLat2 = $ lat2 * (PI/180); $ a = $ radLat1-$ radLat2; $ B = ($ lng1 * (PI/180)-($ lng2 * (PI/180 )); $ s = 2 * asin (sqrt (pow (sin ($ a/2), 2) + cos ($ radLat1) * cos ($ radLat2) * pow (sin ($ B/2), 2); $ s = $ s * EARTH_RADIUS; $ s = round ($ s * 10000)/10000; return $ s ;}