【问题标题】:Why isn't my google maps API reverse geocoder showing results?为什么我的谷歌地图 API 反向地理编码器不显示结果?
【发布时间】:2012-01-10 18:34:45
【问题描述】:

我正在尝试对我的谷歌地图的纬度和经度进行反向地理编码,并在使用 dragend 完成拖动标记后在窗口中显示标记当前位置的格式化地址。

到目前为止,我已经设法在 dragend 上更新窗口并显示其当前位置的经度和纬度,但我无法使用反向地理编码显示地址。

我已关注网站上的演示并尝试实现它,但无法使其工作。

这是我的代码:

     google.maps.event.addListener(marker, "dragend", function (event) {
        var point = marker.getPosition();
        map.panTo(point);
            document.getElementById("latitude").value = point.lat();
            document.getElementById("longitude").value = point.lng();
            infowindow.setContent('<div><strong>' + marker.getPosition() + '</strong><br>' + address);

            var geocoder = new google.maps.Geocoder();

            geocoder.geocode({latLng: event.latLng}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (results[0]) {
                        infoWindow.setContent(results[0].formatted_address);
                        infowindow.open(map, marker);
                    }
                }
            });

    });

【问题讨论】:

    标签: javascript google-maps reverse-geocoding


    【解决方案1】:

    试试

    geocoder.geocode({latLng: point}, function(results, status) {
    

    example

    【讨论】:

    • 按照附件中的示例,并为其添加了自动完成功能。谢谢你
    猜你喜欢
    • 1970-01-01
    • 2013-07-29
    • 2014-03-10
    • 1970-01-01
    • 1970-01-01
    • 2012-04-10
    • 2014-05-18
    • 2015-07-27
    • 2014-12-17
    相关资源
    最近更新 更多