0

I have a problem : i have an JS Array with 4 coordinates point, normaly created with .push command.

I want to update one of the coordinates, and i try to set it with the key and every time the last item is updated, not the right.

google.maps.event.addListener(map, 'click', function(event) {
    newpoint = parseFloat(event.latLng.lat()) + ',' + parseFloat(event.latLng.lng());
    polymakerctrpoints.push(newpoint);
    polymakerctrtable();
    polymakermarkercpt = polymakerctrpoints.length-1;
    polymakermarkers[polymakermarkercpt] = new google.maps.Marker({
    position: {lat: parseFloat(event.latLng.lat()), lng: parseFloat(event.latLng.lng())},
    map: map,
    icon: '/img/mapnum/number_' + Number(polymakermarkercpt+1) + '.png',
    title: titre
});
    polymakermarkers[polymakermarkercpt].setDraggable(true);
    google.maps.event.addListener(polymakermarkers[polymakermarkercpt], "dragend", function(event) { 
    polymakerctrpoints[polymakermarkercpt]=parseFloat(event.latLng.lat()) + ',' + parseFloat(event.latLng.lng());
    polymakerctrtable();
    });
});

When i set « polymakerctrpoints[polymakermarkercpt]=parseFloat(event.latLng.lat()) + ',' + parseFloat(event.latLng.lng()); polymakerctrtable(); » .... the id, on variable polymakermarkercpt is not considerated ... this is every time the last item of the array that will be updated.

We are in a Google Map Javacript API V3 ... and the rest of the script is working very fine.

Thank you for your help !

Swiss GeckO
  • 11
  • 1
  • 3
  • All [your variables are global](http://blog.niftysnippets.org/2008/03/horror-of-implicit-globals.html) because you forgot `var`, and the last `polymakermarkercpt` assignment will overwrite the previous value – Bergi May 13 '17 at 08:01
  • What do you mean by `id, on variable polymakermarkercpt is not considerated`? – Pankaj Shukla May 13 '17 at 08:05

0 Answers0