Looking for assistance with my code. I have a for loop that contains a setTimeout function which calls the server every second and receives a response. However, when trying to access the server response, it returns undefined. Here is my code snippet:
for (let i = 0; i <= latlng.length; i++) {
setTimeout(function() {
GeoCoder.geocode({
'address': latlng[i],
}, function(results, status) {
if (results) {
var lng = results[0].geometry.location.lng()
var lat = results[0].geometry.location.lat()
}
console.log("are we getting location", lng + "" + lat)
});
}, i * 250);
}