[英]Google Maps API: reverse geocoding and address printing
I created a map with a bunch of different locations, each with a type of marker and a title/description. 我创建了具有许多不同位置的地图,每个位置都有一种标记和一个标题/说明。 What I'd like to do is extract from lat/lng the relative address.
我想从lat / lng中提取相对地址。 I found this function which should do what I'm looking for.. but I can't understand how to apply it to my existing code.
我找到了该功能 , 该功能应该可以满足我的要求。.但是我不明白如何将其应用于现有代码。 Here's my fiddle .
这是我的小提琴 。
I'm looking for a way to output the address here: 我正在寻找一种在这里输出地址的方法:
infoWindow.setContent('<h3>' + this.title + '</h3>' + data.description);
Should be something like 应该是这样的
infoWindow.setContent('<h3>' + this.title + '</h3>' + data.description + results[0].formatted_address);
Call the reverse geocoder in the click listener for the marker, open the infowindow with the appended address when the callback returns successfully: 在点击侦听器中调用标记的反向地址解析器,然后在回调成功返回时打开带有附加地址的信息窗口:
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.