I have this code to add to Leaflet map marker genereted by JSON file
jQuery().ready(function (){ 
$.getJSON(
    '/EUREKA/json/map_container/json_map_container.php',
    function(data){
        for ( var i=0; i < data.length; ++i )
        {
            k=i;
            var myIcon = L.icon({
            iconUrl: 'maps/images/' + data[i].type + '.png',
            iconRetinaUrl: 'maps/images/' + data[i].type + '.png',
            iconSize: [42, 55],
            iconAnchor: [9, 21],
            popupAnchor: [0, -14]
            });
            markerArray[i] = L.marker( [data[i].latitude, data[i].longitude], {id: data[i].id, icon: myIcon, draggable:'true'} )
            .bindPopup( '<div>' + '<b>PDL di riferimento:</b> ' + data[i].codice + '<br/>'
                + '<b>Riferimento appaltatore:</b> '
                + data[i].companyId + '<br/>'
                + '<b>Tipo contenitore:</b> '
                + data[i].type + '<br/>'
                + '<b>Numero RDP:</b> '
                + data[i].rdpNumber + '<br/>'
                + '<b>Preposto di riferimento:</b> '
                + data[i].preposto + '<br/>'
                + '<b>Descrizione del rifiuto:</b> '
                + data[i].description
                + '</div>',
                {direction: 'left'} )
            .addTo( map );
            //markerArray[i] = marker1;
            markerArray[i].on('dblclick', function(e){                  
                console.log("ID Marker Array: " + markerArray[k].options.id);
                var latitudeMarker = markerArray[k].getLatLng().lat;
                var longitudeMarker = markerArray[k].getLatLng().lng;
                $.getJSON(
                '/EUREKA/json/map_container/json_update_position.php?&lat=' + latitudeMarker + '&lng=' + longitudeMarker + '&id=' + markerArray[k].options.id,
                function(data){
                    console.log("Posizione aggiornata")
                });
            });
        }
});
The JSON 'json_map_container.php' file return date from a sql query. I want to update the position of a marker in the map when i drag it in a new position at the doubleclick event, I think to call a JSON 'json_update_position.php' with new position and id of marker and The JSON execute a UPDATE query on my db but when I doubleclick on marker I have ever the last id generated. Can anyone help me?
 
    