官方文档:https://lbs.qq.com/service/webService/webServiceGuide/webServiceGcoder
这里使用签名校验的方式,可在腾讯地图控制台KEY管理里查看
/**
* [get_geocoder_location 腾讯地图逆地址解析]
* @param [float] $lng [description]
* @param [float] $lat [description]
* @return [array] [description]
* @document https://lbs.qq.com/service/webService/webServiceGuide/webServiceGcoder
*/
function get_geocoder_location($lng, $lat) {
$sign_key = 'XXXXXXXXX'; //签名校验的KEY
$map_ak = 'AK';
$sign = md5('/ws/geocoder/v1?key='.$map_ak.'&location='.$lat.','.$lng.$sign_key);
$url = 'https://apis.map.qq.com/ws/geocoder/v1?key='.$map_ak.'&location='.$lat.','.$lng.'&sig='.$sign;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36');
$content = curl_exec($ch);
curl_close($ch);
$result = [];
if($content) {
$result = json_decode($content, true);
}
return $result;
}