【问题标题】:Google Maps API open multiple info windows by defaultGoogle Maps API 默认打开多个信息窗口
【发布时间】:2014-02-02 18:21:00
【问题描述】:

是否可以默认打开所有信息窗口。我尝试了以下方法,但它不起作用:

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);
}

【问题讨论】:

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


【解决方案1】:

您的代码只包含一个信息窗口,如果您希望它们全部打开,您需要为每个标记创建一个信息窗口。

更新:在我写这篇文章时没有注意到这个问题被标记为google-maps-api-2。此答案仅适用于Google Maps Javascript API v3the deprecated Google Maps Javascript API v2,一次仅支持一个信息窗口。

// 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);
}

【讨论】:

  • infowindow创建局部变量解决我的问题+1
猜你喜欢
  • 1970-01-01
  • 2016-02-16
  • 2013-02-13
  • 2011-03-31
  • 1970-01-01
  • 1970-01-01
  • 2019-06-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多