Calculate the distance according to the latitude and longitude, and convert Baidu to GPS coordinates (PHP version) & lt ;? Php // Convert Baidu coordinates to GPS coordinates $ lnglat = '2017. 437518, 31.224665 '; functionFromBaiduToGpsXY ($ lnglat) {// longitude, latitude $ lnglat = exp calculate the distance formula based on latitude and longitude, Baidu convert coordinates 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;} // function P2PDistance ($ latlng1, $ latlng2) {// latitude 1, Longitude 1 ~ Latitude 2, longitude 2 $ latlng1 = explode (',', $ latlng1); $ latlng2 = explode (',', $ latlng2); list ($ lat1, $ lng1) = $ latlng1; list ($ lat2, $ lng2) = $ latlng2; $ EARTH_RADIUS = 6378.137; $ radLat1 = fn_rad ($ lat1); $ radLat2 = fn_rad ($ lat2 ); $ a = $ radLat1-$ radLat2; $ B = fn_rad ($ lng1)-fn_rad ($ lng2 ); $ 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 number_format ($ s, 2);} echo 'Baidu coordinate: ', $ lnglat ,'
',' GPS coordinates after conversion: ', FromBaiduToGpsXY ($ lnglat ),'
'; Echo' distance before conversion: ', P2PDistance ('31. 224286666667,121.420675', '31. 224665,121.437518 '),'
'; Echo' distance after conversion: ', P2PDistance ('31. 100', '31. 100');?>