[英]Google Maps API: reverse geocoding and address printing
我創建了具有許多不同位置的地圖,每個位置都有一種標記和一個標題/說明。 我想從lat / lng中提取相對地址。 我找到了該功能 , 該功能應該可以滿足我的要求。.但是我不明白如何將其應用於現有代碼。 這是我的小提琴 。
我正在尋找一種在這里輸出地址的方法:
infoWindow.setContent('<h3>' + this.title + '</h3>' + data.description);
應該是這樣的
infoWindow.setContent('<h3>' + this.title + '</h3>' + data.description + results[0].formatted_address);
在點擊偵聽器中調用標記的反向地址解析器,然后在回調成功返回時打開帶有附加地址的信息窗口:
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.