I have the following for loop:
for (loc in locations){
var newLoc = locations[loc].split(", ")
var uniquevar = new google.maps.Marker({
position: new google.maps.LatLng(newLoc[0], newLoc[1]),
map: map,
title: loc
});
google.maps.event.addListener(loc, 'click', function() {
console.log(loc);
});
};
I't suppose to generate a bunch of map-markers and console.log their name (loc) when you click them. But they all end up console.logging the last item in locations log.
I assume this is because they are all named the same thing
Why is this and what can I do about it?