【发布时间】: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