【问题标题】:Convert lat,lng into Address and show on infoWindow google map api将 lat,lng 转换为地址并在 infoWindow google map api 上显示
【发布时间】:2015-07-03 07:44:29
【问题描述】:

我在对象中有 lat、lng 值的列表

var path = [{"lat":"12.9247903824","lng":"77.5806503296"},{"lat":"10.9974470139","lng":"76.9459457397"}]

在这里,我必须将 latlng 转换为地址,并且必须显示标记和信息窗口。地址必须显示在信息窗口中

我试过这个,我有地址和多个标记,但我无法在信息窗口上显示地址.. 最后一个信息窗口只显示地址

for (var i = 0; i < path.length; i++) {
    var pos = new google.maps.LatLng(path[i]["lat"], path[i]["lng"]);

    var marker = new google.maps.Marker({
        position: pos,
        map: map
    });

    geocoder.geocode({'latLng': pos}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            infowindow.setContent(results[i].formatted_address);
        } else {
            alert('Geocoder failed due to: ' + status);
        }
    });
}

【问题讨论】:

  • 您正在遍历坐标数组,获取每个坐标的地址,然后更新单个信息窗口的内容。当循环结束时,该信息窗口的内容将是这些坐标中最后一个的地址。将代码添加到您创建信息窗口的问题中,以获得有用的答案。
  • 请提供一个Minimal, Complete, Tested and Readable example 来证明这个问题。

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


【解决方案1】:

当你点击一个标记时,你有一个监听器来打开信息窗口吗?在该侦听器中插入地理编码器功能,执行地理编码,将内容设置到信息窗口,然后打开信息窗口。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    相关资源
    最近更新 更多