【问题标题】:Google Map API V3 geocoder not showing the correct placeGoogle Map API V3 地理编码器未显示正确的位置
【发布时间】:2011-02-25 11:55:53
【问题描述】:

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

在 V3 中,我看到了 google.maps.Geocoder() 并尝试获取类似的详细信息。但是,V3 函数给出的 lat & long 是不准确的。

请在此处查看以下屏幕截图:

我的 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 中获得准确的结果?谢谢。

【问题讨论】:

  • 我注意到,在 V3 中,当我搜索业务时,它只会将我带到大约位置(至少从我所在的位置,菲律宾)。由于我无法让 V3 和 Localsearch 一起工作,我决定使用 V2 和 Localsearch 来代替。我使用 V2 地理编码,然后使用 Localsearch 来显示标记。

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


【解决方案1】:

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

贴出addMarker方法代码。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-14
      • 1970-01-01
      • 1970-01-01
      • 2013-07-10
      • 1970-01-01
      • 1970-01-01
      • 2013-04-05
      • 1970-01-01
      相关资源
      最近更新 更多