I'm having an issue with a for loop that creates more than 100 markers. Every time I drag a random marker, the console logs the same position even though the "Point" value is different when dragging another marker. Why am I consistently getting the same position? Interestingly, when I test it with only 1 marker, the code works as expected.
Here's a snippet of the code:
coordinates.forEach(function(entry) {
if(!isOdd(number)){
marker_lat = entry;
number++;
} else {
marker_lng = entry;
var myLatlng = new google.maps.LatLng(parseFloat(marker_lat),parseFloat(marker_lng));
marker_icon = "red.png";
mark = new google.maps.Marker({
position: myLatlng,
map: map,
title: number,
icon: marker_icon,
draggable:true
});
number++;
google.maps.event.addListener(mark, 'dragend', function() {
id_point = $(this).attr("title");
console.log("Point: "+id_point);
console.log(mark.getPosition().lat());// Always the same position
console.log(mark.getPosition().lng());// Always the same position
});
}
});