Calculate the distance from the latitude and longitude of the formula, Baidu coordinates converted to GPS coordinates (PHP version)
Error = = 0) {$bx = Base64_decode ($json->x); $by = Base64_decode ($json->y); $GPS _x = 2 * $x-$bx; $GPS _y = 2 * $y-$by; return $GPS _x ', '. $GPS _y;//longitude, latitude} else return $lnglat;} /**********************************************/function Fn_rad ($d) {return $d * PI ()/180.0;} 2-point algorithm function p2pdistance ($latlng 1, $latlng 2) {//latitude 1, Longitude 1 ~ Latitude 2, Longitude 2$latlng1 = explode (', ', $latlng 1); $LATLNG 2 = Explode (', ', $latlng 2); list ($lat 1, $lng 1) = $latlng 1;list ($lat 2, $lng 2) = $latlng 2; $EARTH _radius = 6378.137; $radLat 1 = Fn_rad ($ LAT1); $radLat 2 = Fn_rad ($lat 2); $a = $radLat 1-$radLat 2; $b = Fn_rad ($lng 1)-Fn_rad ($lng 2); $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 Number_format ($s, 2);} Echo ' Baidu coordinates: ', $lnglat, '
', ' converted GPS Coordinates: ', Frombaidutogpsxy ($lnglat), '
'; Echo ' before conversion distance: ', p2pdistance (' 31.224286666667,121.420675 ', ' 31.224665,121.437518 '), '
'; Echo ' converted distance: ', p2pdistance (' 31.224286666667,121.420675 ', ' 31.220157068379,121.42647022694 ');? >