I will be very thankful if anyone can point out my mistake. One of the online tutorial link me to this tutorial Adding multiple markers with infowindows (Google Maps API) on how to display each pop up windows with their own content. I've visited other similar post on Stack Overflow but It's been a whole days and I can't really work my head around on this one.
Goal:
each marker on Google Maps
will show the restaurant location. Each location has one or more chef's recommend.
when user click on the marker it will bring up the Google Maps pop up info windows
The pop up windows info content only show the chef's recommend that has been assigned to that particular restaurant (each resutrant can have more than one chef's recommend).
What I already achieve:
Each marker position has retrieve and shown correctly on the Google Maps from the database.
Each marker has their own pop up windows.
Each pop up info windows are able to show content.
Problem:
Each pop up windows on the marker will have the same chef's recommend content that are currently the last row of the database.
Thank you.
// ******** Begin Google Maps ********* //
function initMap() {
var restMarker = "somePathToImage.png";
var map = new google.maps.Map(
document.getElementById('googleMaps'), {
zoom: 17,
center: { lat: gon.locations[0].latitude, lng: gon.locations[0].longitude}
});
// ******** BEGIN WINDOW INFO CONTENT ******** //
for (var x = 0; x < gon.restaurant.length; x++){
var contentString =
'<div id="content1">'+
'<div class="container">'+
gon.restaurant[x].chefRecommend +
'</div>'+
'</div>'
;
}
// ******** END WINDOW INFO CONTENT ******** //
for (var i = 0; i < gon.locations.length; i++){
var gMapsMarker = new google.maps.Marker({
position: { lat: gon.locations[i].latitude, lng: gon.locations[i].longitude},
map: map,
icon: restMarker
});
var gMapsInfo = new google.maps.InfoWindow({
content: contentString,
maxWidth: 250
});
gMapsMarker.gMapsInfo = gMapsInfo;
google.maps.event.addListener(gMapsMarker, 'click', function() {
this.gMapsInfo.open(map, this);
});
}
}