Project requirements: Get the distance between two points according to the latitude and longitude, I use the api of Tencent map here
php code:
/** * Use Tencent map api * Calculate the distance between two geographic coordinates */ function getDistance(){ $key ='Fill in your key'; //Tencent map develops your own application $mode ='driving'; //driving (driving), walking (walking) $from ='Fill in your starting point coordinates'; //For example: 39.14122,117.14428 $to ='Start point coordinates; End point coordinates'; //For example (format: end point coordinates; start point coordinates): 39.10149,117.10199;39.14122,117.14428 $url = 'https://apis.map.qq.com/ws/distance/v1/?mode='.$mode.'&from='.$from.'&to='.$to.'&key='.$key; $info = file_get_contents($url); $info = json_decode($info, true); print_r($info); }1234567891011121314
Print result:
Remarks:
-
For parameter analysis of request parameters and response results, you can see the official document: Tencent Map Official Document
Tips:
-
To calculate the distance between two points, you must get the latitude and longitude in advance, right, here I don’t recommend that you use the Baidu map api to get the latitude and longitude. It is a bit inaccurate. I personally stepped on it.