I need to save the latitude and longitude coordinates of points within an object, and then store all these objects in an array. However, I am encountering an issue where each object is being added to the array multiple times.
Here is the code snippet I am using:
function initMap1() {
var mapDiv = document.getElementById('frame1');
map = new google.maps.Map(mapDiv,{
center: {lat: 3.875083, lng: 11.516110},
zoom: 14,
disableDoubleClickZoom: true
});
var Data = [];
google.maps.event.addListener(map,'dblclick',function(e){
var Object = {};
lat.val(e.latLng.lat());
lng.val(e.latLng.lng());
$('#btn_modal').click(function(){
Object['lat'] = e.latLng.lat();
Object['lng'] = e.latLng.lng();
Object['icone'] = nat.val();
var marker = new google.maps.Marker({
position: {lat:e.latLng.lat(),lng:e.latLng.lng()},
map: map,
icon:'img/icones/'+(nat.val())+'.png',
title: nat.val()
});
});
Data.push(Object);
});
}