I was looking over questions related to setting up markers on a Google map, and though the following works perfectly fine for me, it was different from the other (and accepted) answers. I just wanted to see if I'm doing something incorrect, or just a different way.
Mine:
this
references the marker, and you can pull any data you have associated with it simply by calling it within the loop that creates all of the markers.
google.maps.event.addListener(marker, "click", function(){
infowindow.setContent(this.position.toString());
infowindow.open(this.map, this);
});
Accepted:
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));