I'm using the Gmaps.js api in a little project I'm building and struggling with adding click events within a for loop. Here's the code:
for(var i = 0; i < number; i++) {
var entryTime = data[i].datetime;
map.addMarker({
lat: data[i].lat,
lng: data[i].lng,
click: function(){
alert(entryTime);
}
});
}
However, when clicking the markers I always get the last data element. How can I bind this function to each marker?