繁体   English   中英

Google Maps API:反向地理编码和地址打印

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM