for(i = 0; i < locations.length; i++) {
currentLocation = locations[i];
var mapMarker = new google.maps.Marker ({
position: locations[i][0],
map: map,
label: labels[i],
title: locations[i][1],
zoom: 18
})
mapMarkers.push(mapMarker);
mapMarkers[i].addListener('click', markerClick(currentLocation));
}
function markerClick(location) {
console.log("you clicked " + location)
}
The function markerClick is being called each time it is added to an element. How can i make it so it is only called when the element is clicked? i read in another answer herethat leaving out the () would fix this, but I need to pass a paramater and am not sure how to do this. thanks for any help