Google Map API V3 地理编码器未显示正确的位置
我正在将我的代码从 Google Map API V2 升级到 V3。 在 V2 中,我使用 GlocalSearch 来获取给定地址的纬度和经度。
在 V3 中,我看到了 google.maps.Geocoder() 并尝试获取类似的细节。然而,纬度和纬度V3 函数给出的 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中获得准确的结果?谢谢。
I am upgrading my codes from Google Map API V2 to V3.
In V2, I used GlocalSearch to get the latitude and longitude for the given address.
In V3, I saw google.maps.Geocoder() and try to get the similar detail. However, the lat & long given by the V3 function is not accurate.
Pls see the following screenshot here:
My codes for V3 are as follow:
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);
}
});
}
}
Is there better way to get the accurate result in API V3? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
记录位置属性的值并检查坐标是否正确。
发布 addMarker 方法代码。
Log the value of the location property and check if the coordinates are correct.
Post the addMarker method code.
另一种选择是调用 Web 服务,这将产生 JSON 或 XML 格式的结果,然后您可以制定这些结果以获得所需的位置。谷歌地图 v3 文档中有很多示例
Another option is to call the web service which will result results in either JSON or XML format and then you can formulate these results to get the desired location. There are plenty of examples on google maps v3 documentation