首页 文章

为什么我的谷歌 Map API反向地理编码器没有显示结果?

提问于
浏览
0

我试图反转地理编码我的谷歌 Map 的纬度和经度,并在我用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);
                    }
                }
            });

    });

1 回答

  • 3

    尝试

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

    example

相关问题