Currently, I am facing an issue within my Google Maps code that is actually stemming from an architectural problem. Due to a high volume of requests, Google Maps sometimes limits the response, prompting the need for an additional request with a delay. However, when I try to call function2 again in this scenario, it returns an error stating "array is not defined".
function1() {
var array = JSON.parse(xmlhttp.responseText);
for (i; i < length; < i++) {
function2(array[i].one, array[i].two);
}
function3() {
//render directions
}
function2(start, end) {
directionsService.route({
origin: start,
destination: end,
},
function(result, status) {
if (status == google.maps.DirectionsStatus.OK)
function3(result);
else if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT)
var functionStr = "function2(array[i].one" + ',' + "array[i].two)";
setTimeout(functionStr, 5000);
});
}
}