当前位置:网站首页>PHP calls map API

PHP calls map API

2022-06-25 04:53:00 Kiway.

PHP Call up the map API Reverse address resolution

Because the company needs to use the reverse address resolution of the map , To put it simply, longitude and latitude are converted into address information , I found it mainly according to the charge , As the company is involved in foreign business , Gaode map needs to charge for obtaining foreign longitude and latitude information , So I only know about Tencent maps and Baidu maps API.

Tencent map API

 Pass parameters into the method , Finally, use this link to call 
(key The last string is obtained by registering and logging in , This item is false key, Just Tencent maps key The type of use is '-' Connected )
$url = 'https://apis.map.qq.com/ws/geocoder/v1/?location= '.$data['lat'].','.$data['lng'].'&key=HJOTq-QWAO1P-F1DK-Q132-1RQ5-NWRF3';
$urlContent = file_get_contents($url);
$urlContent = json_decode($urlContent, true);
// Get address information 
$res->address .= $urlContent['result']['address']??'';

Put the link directly on the browser to print the effect picture :
 Insert picture description here
Baidu Maps API

 Pass parameters into the method , Finally, use this link to call 
(ak The last string is obtained by registering and logging in , This item is false ak, Just Tencent maps ak The type of is a string )
 $url = 'http://api.map.baidu.com/reverse_geocoding/v3/?ak=asSFSioIUQWtxVqeASDSAQWE41125ASDsad&output=json&coordtype=wqedsfasdq4112wqe&location=' . $res->lat . "," . $res->lng;
// Analysis of Baidu url
$urlContent = file_get_contents($url);
$urlContent = json_decode($urlContent, true);
//  according to url Output address 
$res->address .= $urlContent['result']['formatted_address'];

Put the link directly on the browser to print the effect picture :
 Insert picture description here

Other interfaces are similar , You can get to their API see , Now many situations involve charging , Be careful to ask .

原网站

版权声明
本文为[Kiway.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202210533123109.html