Based on the latitude and longitude calculation distance formula, Baidu coordinates converted to GPS coordinates (PHP version)

Source: Internet
Author: User
Tags cos pow
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 ');? >
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.