Looping through Markers with Google Maps API v3 Problem
You are having a very common closure problem in the following loop: for(x in locations){ console.log(x); infowindow[x] = new google.maps.InfoWindow({content: x}); marker[x] = new google.maps.Marker({title:locations[x][0],map:map,position:locations[x][2]}); google.maps.event.addListener(marker[x], ‘click’, function() {infowindow[x].open(map,marker[x]);}); } Variables enclosed in a closure share the same single environment, so by the time the click callbacks are executed, the loop has run its course … Read more