谷歌地图地理代码,包括房屋名称



使用下面的代码运行良好:

function geocode($address){
$return = array();
$address = urlencode($address);
$key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$url = "https://maps.google.com/maps/api/geocode/json?key=$key&address={$address}";

if (!function_exists("curl_init")){
load_curl();
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT,6000);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
$resp_json = curl_exec($ch);
curl_close($ch);

$resp = json_decode($resp_json, true);
if($resp['status']!=='OK') return false;
foreach($resp['results'] as $res){
$loc = array(
"zipcode"=>null,
"formatted"=>null
);
foreach($res['address_components'] as $comp){
if(in_array("postal_code", $comp['types'])) 
$loc['zipcode'] = $comp['short_name'];
}
$loc['formatted'] = $res['formatted_address'];
$loc['lng'] = $res['geometry']['location']['lng'];
$loc['lat'] = $res['geometry']['location']['lat'];
$return[] = $loc;
}
return $resp;
}

但是,当我搜索诸如">ZOOM DIGITAL PRINT UNIT 36 BINLEY IND EST HOTCHKISS WAY COVENTRY CV3 2RL"之类的地址时,格式化后的地址会返回为">Starley Court,HOTCHKISS WAY,COVENTRY CV3 2RL,UK">

是否有方法获取此请求中包含的业务名称,或者可以由另一个API找到该名称?

地理编码API用于将地址转换为lat/lng坐标,反之亦然,或用于查找给定位置ID的地址。

要获取商业信息,您应该使用Places API。例如,尝试在谷歌的自动完成示例中搜索"Zoom Digital Print Ltd",你会得到这个企业名称。

希望这能有所帮助!

相关内容

  • 没有找到相关文章