[英]Google Maps, geocoder, javascript: when don't find an address, put marker in the center
I'm doing a page with geocode, it's working well, but always come in the array of addresses places that it's not catalogated in google maps. 我正在用地理编码制作一个页面,它工作正常,但总是出现在未在Google地图中分类的地址位置数组中。 Unfortunatly, the geocoder, instead of not doing nothing, put the marker of the not found address in the center of the map.
不幸的是,地理编码器没有执行任何操作,而是将未找到地址的标记放置在地图的中心。
There's some code to make the geocoder not put this not found marker? 有一些代码可以使地址解析器不放置未找到的标记?
(I'm brazilian, my english it's bad, sorry =)) (我是巴西人,我的英语不好,对不起=))
function addMarker(position) {
var geocoder;
geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': address[position]}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
places[position] = results[0].geometry.location;
var marker = new google.maps.Marker({
position: places[position],
map: mapa,
icon: icone,
title: ('OS: ' + arOS[position] + ' - ' + arEndereco[position]),
url: 'OSDETALHES.asp?txtCodigoOS=' + arOS[position]
});
google.maps.event.addListener(marker, 'click', function() {
window.open(this.url, '_blank');
});
}
else
{
if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT)
{
setTimeout(function() { addMarker(position); }, (timeout * 3));
}
}
address_position++;
if (address_position < address.length)
{
setTimeout(function() { addMarker(address_position); }, (timeout));
}
});
}
}
You should be looking at Geocoding Results to determine how well Geocoding worked. 您应该查看地理编码结果,以确定地理编码的效果如何。
geometry contains the following information: 几何包含以下信息:
location_type stores additional data about the specified location. location_type存储有关指定位置的其他数据。 The following values are currently supported:
当前支持以下值:
Updated Per Comments 每个评论已更新
I have not used this, but something very close to this should work: 我没有使用过,但是很接近的东西应该可以工作:
if (results[0].geometry.location.location_type != 'ROOFTOP')
{
// not an exact match
}
RANGE_INTERPOLATED, apparently, solved my problem: RANGE_INTERPOLATED,显然解决了我的问题:
if (results[0].geometry.location_type == google.maps.GeocoderLocationType.RANGE_INTERPOLATED){
Thanks, Erik. 谢谢,埃里克。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.