Question

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);
}
Was it helpful?

Solution

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top