I am trying to add a timeout delay to a for loop. It currently loops through locations in a variable and places a marker for all in it. It works fine but I would like it to show them with a slight time delay. I am trying to use setTimeOut function but when I add it, it cant load the data?
The loop working before I add the timeout is
for (var i = 0; i < data.length; i++) {
if (data[i].lat != null) {
markers[data[i].username]= new L.marker([data[i].lat, data[i].lng], { bounceOnAdd: true,draggable: true, icon: redIcon });
map.addLayer(markers[data[i].username]);
markers[data[i].username].bindPopup('Online :' + data[i].username);
}
And what doesnt work with the timeout added.
for (var i = 0; i < data.length; i++) { setTimeout(function () {
if (data[i].lat != null) {
markers[data[i].username]= new L.marker([data[i].lat, data[i].lng], { bounceOnAdd: true,draggable: true, icon: redIcon });
map.addLayer(markers[data[i].username]);
markers[data[i].username].bindPopup('Online :' + data[i].username);
}, 3000);
}