问题
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);
}
回答1:
Your code only includes one infowindow, if you want them all to open, you need to create an infowindow for each marker.
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);
}
来源:https://stackoverflow.com/questions/21514388/google-maps-api-open-multiple-info-windows-by-default