我正在研究 JavaScript Google Map API(版本 3),更准确地说,正在研究反向地理定位。在...的帮助下官方文档 http://code.google.com/intl/fr/apis/maps/documentation/geocoding/#ReverseGeocoding,我成功进行了反向地理编码,找到了经纬度坐标对应的地址。
但我找不到如何到达与该地址绑定的名称。是否可以?怎样才能执行呢?
感谢您。
卡米尔。
您确实需要循环并对谷歌在这些点找到的内容进行多次检查,一个小脚本来实际读取/循环返回的数据将是(在 PHP 中):
<?php
$data = json_decode(file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?latlng=46.1124,1.245&sensor=true"));
if($data->status == "OK") {
if(count($data->results)) {
foreach($data->results as $result) {
echo $result->formatted_address . "<br />";
}
}
} else {
// error
}
?>
现在根据文档:
请注意,反向地理编码器
返回多个结果。 ...ETC
And:
一般来说,地址是从
最具体到最不具体;这
更准确的地址是最
显着的结果...等
您只需要第一个结果即可获得您想要的结果(或者至少在那里搜索它$data->results[0]->
.
所以请阅读types http://code.google.com/intl/fr/apis/maps/documentation/geocoding/#Types并在此基础上您可以检查是否出现您想要的结果:
<?php
$data = json_decode(file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?latlng=46.1124,1.245&sensor=true"));
if($data->status == "OK") {
if(count($data->results)) {
foreach($data->results[0]->address_components as $component) {
if(in_array("premise",$component->types) || in_array("route",$component->types) || in_array("park",$component->types)) {
echo $component->long_name . "<br />";
}
}
}
} else {
// error
}
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)