简体   繁体   English

Google地图,地理编码器,JavaScript:找不到地址时,将标记放在中间

[英]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: 当前支持以下值:

  • google.maps.GeocoderLocationType.ROOFTOP indicates that the returned result reflects a precise geocode. google.maps.GeocoderLocationType.ROOFTOP表示返回的结果反映了精确的地理编码。
  • google.maps.GeocoderLocationType.RANGE_INTERPOLATED indicates that the returned result reflects an approximation (usually on a road) interpolated between two precise points (such as intersections). google.maps.GeocoderLocationType.RANGE_INTERPOLATED表示返回的结果反映了在两个精确点(例如交叉点)之间插值的近似值(通常在道路上)。 Interpolated results are generally returned when rooftop geocodes are unavailable for a street address. 当街道地址无法使用屋顶地理代码时,通常会返回插值结果。
  • google.maps.GeocoderLocationType.GEOMETRIC_CENTER indicates that the returned result is the geometric center of a result such as a polyline (for example, a street) or polygon (region). google.maps.GeocoderLocationType.GEOMETRIC_CENTER表示返回的结果是结果的几何中心,例如折线(例如,街道)或多边形(区域)。
  • google.maps.GeocoderLocationType.APPROXIMATE indicates that the returned result is approximate. google.maps.GeocoderLocationType.APPROXIMATE表示返回的结果是近似值。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM