0

我創建了一個包含一系列不同位置的地圖,每個位置都有一種標記和一個標題/描述。我想要做的是從lat/lng中提取相對地址。我發現this function應該做我正在尋找..但我不明白如何將其應用於我現有的代碼。這裏是my fiddleGoogle Maps API:反向地理編碼和地址打印

我正在尋找一種方式來輸出的地址在這裏:

infoWindow.setContent('<h3>' + this.title + '</h3>' + data.description); 

應該像

infoWindow.setContent('<h3>' + this.title + '</h3>' + data.description + results[0].formatted_address); 
+0

你寫了「我找到了這個函數」,那是什麼函數? – geocodezip 2014-08-29 23:26:59

+0

ops,對不起。忘了鏈接。添加。 – MultiformeIngegno 2014-08-30 00:14:23

回答

0

updated fiddle

呼叫在點擊監聽器的反向地理編碼標記,當回調成功時,打開帶附加地址的infowindow:

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); 
相關問題