I have a problem with displaying infowindows in Google Maps; currently, it only shows the information for the last marker added.
let myLatlng = new window.google.maps.LatLng(-33.890542, 151.274856 );
let mapOptions = {
zoom: 13,
center: myLatlng,
scrollwheel: true,
};
var locations = [
['Bondi Beach', -33.890542, 151.274856, 4],
['Coogee Beach', -33.923036, 151.259052, 5],
['Cronulla Beach', -34.028249, 151.157507, 3],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Maroubra BeachManly Beach Manly Beach Manly Beach', -33.950198, 151.259302, 1]
];
let map = new window.google.maps.Map(
document.getElementById("map"),
mapOptions
);
var count;
var markers=[];
for (count = 0; count < locations.length; count++) {
markers.push(new google.maps.Marker({
position: new google.maps.LatLng(locations[count][1], locations[count][2]),
map: map,
title: locations[count][0]
}));
}
var infowindow = new google.maps.InfoWindow({
content:"<div></div>"
});
markers.forEach(function(marker) {
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
});