【问题标题】:retrieve latitude and longitude in google map [duplicate]在谷歌地图中检索纬度和经度[重复]
【发布时间】:2013-02-23 22:02:08
【问题描述】:

我可以在地图上设置图钉,但我无法检索该点的纬度和经度。这是我的代码。有人可以帮忙吗?

谢谢

 function codeaddress() {
    var geocoder;
    //map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    geocoder = new google.maps.Geocoder();

    var address = document.getElementById("address").value;

    geocoder.geocode({ 'address': address }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {


            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                animation: google.maps.Animation.BOUNCE,
                flat: false,
                map: map,
                position: results[0].geometry.location

            });

            var latt = document.getElementById("latitude");
            latt.value = results[0].geometry.location.getlatitude();
            alert(latt.value);

        } else {
            alert("Geocode was not successful for the following reason: " + status);
        }
    });

}

【问题讨论】:

  • 这需要先进行基本调试。到底哪里出了问题?
  • 你试过 results[0].geometry.location.lat()
  • Rafe,尝试了结果[0].geometry.location.lat()。没有得到纬度。
  • Chrome 未显示更新的页面。当我运行应用程序时,我在 javascript 中所做的任何代码更改都没有反映出来。稍后添加了我试图检索纬度和经度的代码部分。这些变化没有反映出来。当我在 chrome 上删除浏览历史记录时,我能够看到更改。

标签: javascript asp.net google-maps


【解决方案1】:

尝试使用.lat() 而不是.getLatitude()

请参阅有关 LatLng 类的 API:https://developers.google.com/maps/documentation/javascript/reference#LatLng

【讨论】:

  • klassman,我也尝试了 .lat(),结果相同。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-09
  • 1970-01-01
相关资源
最近更新 更多