Google Map API V3地理编码器未显示正确的位置

时间:2010-05-29 14:18:38

标签: javascript geocoding google-maps-api-3

我正在将我的代码从Google Map API V2升级到V3。 在V2中,我使用GlocalSearch获取给定地址的纬度和经度。

在V3中,我看到了google.maps.Geocoder()并尝试获得类似的细节。但是,lat&由V3功能给出的长期不准确。

请在此处查看以下屏幕截图: Wrong http://img340.imageshack.us/img340/477/wronga.jpg Correct http://img413.imageshack.us/img413/5899/correct.jpg

我的V3代码如下:

var geocoder = new google.maps.Geocoder();
function codeAddress(address) {
    if (geocoder) 
    {
        address = address + ", UK";

        geocoder.geocode( { 'address': address}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                var latlng = results[0].geometry.location;              
                addMarker(latlng); //Adding Marker here             
            } else {
                alert("Geocode was not successful for the following reason: " + status);
            }
        });
    }
}

有更好的方法可以在API V3中获得准确的结果吗?感谢。

2 个答案:

答案 0 :(得分:0)

记录location属性的值并检查坐标是否正确。

发布addMarker方法代码。

答案 1 :(得分:0)

另一种选择是调用Web服务,该服务将产生JSON或XML格式的结果,然后您可以制定这些结果以获得所需的位置。谷歌地图v3文档中有很多例子