为什么不是'我的谷歌地图API反向地理编码显示结果

Why isn't my google maps API reverse geocoder showing results?

本文关键字:编码 结果 显示 API 谷歌地图 我的 为什么不      更新时间:2023-09-26

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

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

我已经在网站上跟踪了演示,并试图实现它,但可以;it’我不能让它发挥作用。

这是我的代码:

     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);
                    }
                }
            });
    });

尝试

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

example