I am using Google maps JavaScript API creating multiple markers with popups (InfoWindow)
function initMap(){
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 2,
center: {lat: 20, lng: 0}
});
//console.log(dbResults);
for(var i=0; i<dbResults.length; i++){
var _coords = dbResults[i].location.split(',');
var coords = {lat: parseFloat(_coords[0]), lng: parseFloat(_coords[1])}
//console.log(coords);
var marker = new google.maps.Marker({
position: coords,
map: map
});
var infowindow = new google.maps.InfoWindow({
content: '<div>'+dbResults[i].title+'</div>'
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
}
}
The markes appear properly around the map, but the popups are shown only at the center of the map (instead of appear near the belonging marker position)
What do I need to change in order to make them work?