【问题标题】:How to retrieve full street address from marker placement (Reverse Geocoding)?如何从标记放置(反向地理编码)中检索完整的街道地址?
【发布时间】:2015-11-10 14:36:45
【问题描述】:

我希望能够在地图上放置一个标记并让它显示完整的地址,包括街道号码和名称。

目前,我有点工作,但由于我不明白的原因,这只会检索放置标记的郊区名称,即使我放大并将标记放在建筑物上。

我正在关注反向地理编码示例here,将其与添加标记脚本结合使用。

有人知道在放置标记时如何检索完整地址吗?

我的代码是:

function addMarker(location) {

  geocoder.geocode({'location': location}, function(results, status) {
    if (status === google.maps.GeocoderStatus.OK) {
      if (results[1]) {
        map.setZoom(16);
        var marker = new google.maps.Marker({
          position: location,
          map: map
        });
        markers.push(marker);
        infowindow.setContent(results[1].formatted_address);
        var markerAddress = results[1].formatted_address;
        console.log(markerAddress);
        infowindow.open(map, marker);
      } else {
        window.alert('No results found');
      }
    } else {
      window.alert('Geocoder failed due to: ' + status);
    }
  });//GEOCODER

}//ADD MARKER

【问题讨论】:

标签: javascript google-maps google-maps-api-3


【解决方案1】:

我必须更改它以获得第一级结果:

infowindow.setContent(results[1].formatted_address);

我不知道他们为什么会这样分手,但是你去吧

【讨论】:

    猜你喜欢
    • 2013-06-08
    • 1970-01-01
    • 2014-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-20
    • 1970-01-01
    相关资源
    最近更新 更多