javascript - Google Map - Add a marker between 2 markers -



javascript - Google Map - Add a marker between 2 markers -

for web application, need allow add together marker between 2 markers.

i have array of markers, , force markers when create one.

my problem, don't arrive have array working. add together marker on map right position, between previous 1 , next one, but, how can force in array in right index ? add together between marker 1 , 2, so, new marker must have index 2, then, old index 2 must have index 3....

` function addmarkerafter(i) {

var lat = (markers[i].getposition().lat() + markers[(i+1)].getposition().lat()) / 2; var lng = (markers[i].getposition().lng() + markers[(i+1)].getposition().lng()) / 2; var marker = new google.maps.marker({ position: new google.maps.latlng(lat, lng), map: map, title: 'number ' + (i+1), draggable: true }); var l = markers.length; (var j=i; j<l; j++) { markers[j+1] = markers[j]; } markers[i] = marker; }`

but, result catastrophic ... there way "push" in array ?

thanks !

oh god ! resolve problem simple line :

markers.splice(i, 0, marker);

sorry !

i think looking array.splice() function (example).

javascript google-maps

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -