简体   繁体   English

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

[英]Google Map API V3 geocoder not showing the correct place

I am upgrading my codes from Google Map API V2 to V3. 我正在将我的代码从Google Map API V2升级到V3。 In V2, I used GlocalSearch to get the latitude and longitude for the given address. 在V2中,我使用GlocalSearch获取给定地址的纬度和经度。

In V3, I saw google.maps.Geocoder() and try to get the similar detail. 在V3中,我看到了google.maps.Geocoder()并尝试获得类似的细节。 However, the lat & long given by the V3 function is not accurate. 但是,V3功能给出的lat和long不准确。

Pls see the following screenshot here: 请在此处查看以下屏幕截图: 错误 正确

My codes for V3 are as follow: 我的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);
            }
        });
    }
}

Is there better way to get the accurate result in API V3? 有没有更好的方法来获得API V3中的准确结果? Thanks. 谢谢。

Log the value of the location property and check if the coordinates are correct. 记录location属性的值并检查坐标是否正确。

Post the addMarker method code. 发布addMarker方法代码。

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. 另一种选择是调用Web服务,该服务将产生JSON或XML格式的结果,然后您可以制定这些结果以获得所需的位置。 There are plenty of examples on google maps v3 documentation 谷歌地图v3文档中有很多例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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