Google Maps API默认打开多个信息窗口 [英] Google Maps API open multiple info windows by default

查看:110
本文介绍了Google Maps API默认打开多个信息窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下是否可以打开所有信息窗口?我尝试了以下方法,但无效:

Is it possible to open all info windows by default. I tried the following but it doesn't work:

var infowindow = new google.maps.InfoWindow({
      maxWidth: 160
});

// Add the markers and infowindows to the map
for (var i = 0; i < locations.length; i++) {
    marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map,
        icon: icons[iconCounter]
    });

    infowindow.setContent(locations[i][0]);
    infowindow.open(map, marker);
}


推荐答案

您的代码只包含一个infowindow ,如果您想让它们全部打开,您需要为每个标记创建一个infowindow。

Your code only includes one infowindow, if you want them all to open, you need to create an infowindow for each marker.

更新:当我写这个问题时,没有注意到这个问题被标记为 google-maps-api-2 。此答案仅适用于 Google Maps JavaScript API v3 已过时的Google Maps Javascript API v2 ,一次只支持一个infowindow。

Update: didn't notice when I wrote this that this question is tagged google-maps-api-2. This answer will only work for the Google Maps Javascript API v3, the deprecated Google Maps Javascript API v2, only supports a single infowindow at a time.

// Add the markers and infowindows to the map
for (var i = 0; i < locations.length; i++) {
    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map,
        icon: icons[iconCounter]
    });

    var infowindow = new google.maps.InfoWindow({
      content: locations[i][0],
      maxWidth: 160
    });
    infowindow.open(map, marker);
}

这篇关于Google Maps API默认打开多个信息窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆