需要这个帮助。谷歌地图API v3返回ZERO_RESULTS,但Maps.Google.com显示罚款
我使用Google Maps API v3获取存储在我的数据库中的人类可读地址的经度和纬度,然后在Google Map画布上放置1个标记。非常简单。
我遇到的问题是,一些地址被踢回的状态代码 - > ZERO_RESULTS
如果键入这些相同的地址到maps.google.com,他们会发现,特定区域并将其映射用一个近似的标记。
我在我的数据库中的一些地址不是特定的,这意味着他们可能没有邮政编码和/或他们可能没有城市,但都有一个省/地区和国家。另外需要注意的是,他们都没有街道地址。
有些人可读的地址可具有破折号( - ),空间(),撇号('),和逗号(,)
被踢回ZERO_RESULTS一个地址的一个例子是:
Soul-t'ukpyolsi, Korea, South
在该特定示例中,国家在名称中包含逗号和空格,并且该地区还有一个撇号和短划线。
这里是我使用的Javascript代码:
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&key=MYKEY&sensor=false"></script>
<script>
function initialize() {
var myLatlng = new google.maps.LatLng(<?php echo $lat; ?>,<?php echo $long; ?>);
var mapOptions = {
zoom: 5,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
我使用PHP生成基于存储在我的数据库地址内容的详细地址路径。下面是我使用生成的路径,然后发出geolocator请求代码:
记住,城市和邮政编码/ ZIP可选的元素
// Replace any spaces in vars
if (isset($gmaps_city)){
$gmaps_city = str_replace(" ","+",$gmaps_city);
}
if (isset($gmaps_province)){
$gmaps_province = str_replace(" ","+",$gmaps_province);
}
if (isset($gmaps_country)){
$gmaps_country = str_replace(" ","+",$gmaps_country);
}
if (isset($gmaps_pcode)){
$gmaps_pcode = str_replace(" ","+",$gmaps_pcode);
}
// If Postal Code and City
if (isset($gmaps_city) AND isset($gmaps_pcode)){
$gmaps_path = $gmaps_city.",+".$gmaps_province.",+".$gmaps_country.",+".$gmaps_pcode."&sensor=false";
// If City but no Postal Code
} else if (isset($gmaps_city) AND !isset($gmaps_pcode)){
$gmaps_path = $gmaps_city.",+".$gmaps_province.",+".$gmaps_country."&sensor=false";
// If Postal Code but no City
} else if (!isset($gmaps_city) AND isset($gmaps_pcode)){
$gmaps_path = $gmaps_province.",+".$gmaps_country.",+".$gmaps_pcode."&sensor=false";
// Only Province and Country
} else {
$gmaps_path = $gmaps_province.",+".$gmaps_country."&sensor=false";
}
// Determine Lat and Long of Address
$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$gmaps_path);
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;
$status = $output->status;
任何帮助是极大的赞赏。
为什么你认为这个地址'Soul-t'ukpyolsi,Korea,South'在谷歌地图中有效?请提供一个好的结果链接(我得到[首尔](https://maps.google.com/maps?q=Soul-t'ukpyolsi,+Korea,+South))。 – geocodezip
相信问题的根源是拼写错误,它应该是 - > Seoul-t'ukpyolsi,韩国,南...相信它在谷歌地图中的作品,因为去Maps.Google.com和输入“灵魂韩国,南韩“(不正确的拼写)确实在首尔放置了一个标记。通过JSON生成ZERO_RESULTS – nmcwilli