Php is used to calculate the distance between Baidu map coordinates. php coordinate _ PHP Tutorial

Source: Internet
Author: User
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 ;}

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.