Why my looping doesnt work. this marker for google maps doesnt work
Clash Royale CLAN TAG#URR8PPP
Why my looping doesnt work. this marker for google maps doesnt work
i try to mark some places use looping with interval time. but actually it doesnt work. marked called just one. this is my code
var count = 4;
var nlat = 0;
var nlng = 0;
var counti = 0;
var map;
var marker;
var old_nlat;
var old_nlng;
var dlat;
var dlng;
var n_lat;
var n_lng;
function activate()
// this my function to activate
old_nlat = nlat;
old_nlng = nlng;
nlat = lks[counti].l1;
nlng = lks[counti].l2;
var myLatLng = lat: nlat, lng: nlng ;
if (marker == null)
marker = new google.maps.Marker(
position: myLatLng,
map: map,
);
else
setTimeout(transition, 500);
counti++;
marker.setMap(map);
function transition()
// this function to transition
j = 0;
dlat = (nlat - old_nlat) / 100;
dlng = (nlng - old_nlng) / 100;
n_lat = old_nlat;
n_lng = old_nlng;
move();
function move()
// this function to my marker is move
n_lat += dlat;
n_lng += dlng;
var n_myLatLng = lat: n_lat, lng: n_lng ;
marker.setPosition(n_myLatLng);
if (j != 100)
j++;
setTimeout(move, 5);
function automark()
// looping in here
do
setTimeout(activate, 500);
var n_myLatLng = lat: n_lat, lng: n_lng ;
marker.setPosition(n_myLatLng);
while (counti < count);
function initAutocomplete()
map = new google.maps.Map(document.getElementById("map"),
zoom: 13,
center: lat: -7.2566169, lng: 112.7142751 ,
);
automark();
window.onload = initAutocomplete;
also what are counti and count. Where is counti incremented?
– Jeremy Kahan
Aug 10 at 4:58
Counti increment when activate is called and count is number 1 set
– Yan Robert Pomo
Aug 10 at 5:04
thanks for the explanation
– Jeremy Kahan
Aug 10 at 12:16
I am thinking things might be running ahead and your globals might not be what you think, including counti, but also maybe once scheduled it keeps referring to the last location (not sure what lks is). See stackoverflow.com/questions/13686085/… for possible enlightenment.
– Jeremy Kahan
Aug 10 at 12:44
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
The first thing that I observed is the syntax error after while loop. Replace '}' with '{' after the loop. Reomove ';' after while condition.
– Saboor
Aug 10 at 4:56