I have integrated Google Maps in my website and i have set the markers on it
When i click on the markers i want to get the same latitude and longitude of that particular using which i have set.
For a test i have set two markers.
When i click on the markers everytime the last set marker’s latitude and longitude is being shown in the console.
how do i resolve this?
for(var gMarker = 0; gMarker < records.length ; gMarker++){
var gMarkerThis = records[gMarker].LatLng;
var marker = new google.maps.Marker({
position: new google.maps.LatLng(gMarkerThis[0], gMarkerThis[1]),
map: map,
title: 'Test'
});
google.maps.event.addListener(gMarkerArray, 'click', function() {
console.log(marker.position , marker.position.lat() , marker.position.lng());
});
}
How about a closure ?
I have no idea what
gMarkerArrayis, but I’ll assume it’s the current marker in the loop, as that is what it should be ?