PHP to calculate Baidu map coordinates the distance between the method of Baidu map bus query Baidu Map API Baidu map Route check

Source: Internet
Author: User
Tags php database php programming php regular expression
In this paper, we describe the method of calculating the distance between Baidu map coordinates by PHP. Share to everyone for your reference, as follows:

The following is the online code, the use of the time needed to make some changes

The first function is to get the range, the parameter is the latitude longitude radius

The second function is to calculate the coordinate distance

<?phpdefine (' PI ', 3.1415926535898);d efine (' Earth_radius ', 6378.137);//compute range, can do search user function GetRange ($lat, $lon,  $raidus) {//Compute latitude $degree = (24901 * 1609)/360.0;  $dpmLat = 1/$degree;  $radiusLat = $dpmLat * $raidus; $minLat = $lat-$radiusLat; Get the minimum latitude $maxLat = $lat + $radiusLat;  Get maximum latitude//calculate Longitude $mpdLng = $degree * cos ($lat * (pi/180));  $dpmLng = 1/$mpdLng;  $radiusLng = $dpmLng * $raidus; $minLng = $lon-$radiusLng; Get the minimum longitude $maxLng = $lon + $radiusLng; Get the maximum longitude//Range $range = Array (' minlat ' = = $minLat, ' Maxlat ' + $maxLat, ' minlon ' = = $minLng, ' Maxlo  n ' = $maxLng); return $range;}  Get distance between 2 points function getdistance ($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;}

More about PHP related content readers can view the topic: "PHP array" operation Skills Daquan, "PHP Math Skills Summary", "PHP Regular Expression Usage Summary", "Php+ajax Tips and Applications Summary", "PHP operation and operator Usage Summary", " PHP Network Programming Skills Summary, PHP Basic Grammar Introductory tutorial, PHP date and Time usage summary, PHP Object-oriented Programming primer tutorial, PHP string Usage Summary, PHP+MYSQL Database Operations primer, and A summary of common PHP database operation techniques

I hope this article is helpful to you in PHP programming.

The above describes the PHP implementation of the calculation of Baidu map coordinates distance between the method, including Baidu map, the method of the content, I hope that the PHP tutorial interested friends have helped.

  • Related Article

    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.