<?php $address = "广东省广州市天河区";
$point = getPoint($address); var_dump($point);//输出经纬度 /**
* 【根据详细地址获取经纬度】
* 20170920
*
* @param $address
* @return array
*/
function getPoint($address){
$url = "http://apis.map.qq.com/jsapi?qt=geoc&addr={$address}}&key=6KLBZ-EW7CV-BVFPV-UUFU2-6STGE-G7BI7&output=jsonp&pf=jsapi&ref=jsapi&cb=qq.maps._svcb3.geocoder0";
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//转为字符串,而不是直接输出 $wetContent = curl_exec($ch); $data = iconv("GB18030", "UTF-8//IGNORE", $wetContent); $match = '/"pointx":"([\s\S]*?)",\s*?"pointy":"([\s\S]*?)"/'; if(preg_match($match,$data,$rst)){
$arr = [
'longitude' => $rst[1],
'latitude' => $rst[2],
];
}else{
$arr = [
'longitude' => '',
'latitude' => '',
];
} curl_close($ch);
return $arr; }