javascript – Google Maps API默认打开多个信息窗口
作者:互联网
是否可以默认打开所有信息窗口.我尝试了以下但它不起作用:
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.
更新:当我写这篇文章时没有注意到这个问题被标记为google-maps-api-2.这个答案只适用于Google Maps Javascript API v3,the deprecated Google Maps Javascript API v2,一次只支持一个infowindow.
// 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-2,javascript,google-maps 来源: https://codeday.me/bug/20191003/1847109.html