我创建了一张包含许多不同位置的地图,每个位置都有一种标记和标题/描述。我想做的是从 lat/lng 中提取相对地址。我发现这个功能 https://developers.google.com/maps/documentation/geocoding/?hl=it#ReverseGeocoding哪个应该做我正在寻找的事情..但我不明白如何将它应用到我现有的代码中。这是我的小提琴 http://jsfiddle.net/multiformeingegno/7n1mwq3c/10/.
我正在寻找一种在这里输出地址的方法:
infoWindow.setContent('<h3>' + this.title + '</h3>' + data.description);
应该是这样的
infoWindow.setContent('<h3>' + this.title + '</h3>' + data.description + results[0].formatted_address);
更新了小提琴 http://jsfiddle.net/7n1mwq3c/11/
在标记的点击侦听器中调用反向地理编码器,当回调成功返回时,打开带有附加地址的信息窗口:
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: data.title,
// animation: google.maps.Animation.DROP,
icon: new google.maps.MarkerImage(icon)
});
(function (marker, data) {
google.maps.event.addListener(marker, "click", function (e) {
geocoder.geocode({
'latLng': marker.getPosition()
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
infoWindow.setContent("<h3>" + marker.title + "</h3>" + data.description + "<br><b>address:</b> "+results[0].formatted_address);
infoWindow.open(map, marker);
} else {
infoWindow.setContent('<h3>' + marker.title + '</h3>' + data.description);
infoWindow.open(map, marker);
}
});
});
})(marker, data);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)