【发布时间】: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