Update marker position on google map without page load
13,734
This code here isn't valid javascript:
setInterval(function() {
position: new google.maps.LatLng(purple[i][1], purple[i][2]),
marker.setPosition(position);
}, 20000);
You want to do:
setInterval(function() {
position = new google.maps.LatLng(purple[i][1], purple[i][2]);
marker.setPosition(position);
}, 20000);
Author by
Alex
Updated on August 09, 2022Comments
-
Alex over 1 year
I'm trying to update the google map marker position in every 20 seconds which comes from database but it's doesn't work.
Code :
for (i = 0; i < purple.length; i++) { if (purple[i][1] == latitude && purple[i][2] == longitude) { nogreen = 1; } marker = new google.maps.Marker({ position : new google.maps.LatLng(purple[i][1], purple[i][2]), map : map, title : purple[i][0], data : purple[i][0], zoom : maxZoomService, icon : 'img/purple.png', shadow : 'img/purple.png' }); setInterval(function () { position : new google.maps.LatLng(purple[i][1], purple[i][2]), marker.setPosition(position); }, 20000); };
Is this correct or how can i do that ?