Skip to main content
Notice removed Authoritative reference needed by CommunityBot
Bounty Ended with no winning answer by CommunityBot
Notice added Authoritative reference needed by Karim Ali
Bounty Started worth 50 reputation by Karim Ali
added 37 characters in body
Source Link
Karim Ali
  • 2.4k
  • 6
  • 25
  • 35

I have two Arrays (gOriginsArray, gDestinationsArray) which are Array of Arrays and I am storing 10 addresses in each array and I have close to 300 origins addresses and 300 destinations address stored in a sets of 10 entries. My gOriginsArray has 300 identical elements. I am running a loop and sending 10 addresses from both array to calculate the distance but my loop carries on before I get result from DistanceMatrixService and I get OVER_QUERY_LIMIT error as well.

I want to find the distance of all 300 addresses and then run LoadBookingsArray(Records) function.

for (var k = 0; k < gDestinationsArray.length; k++) {
  var DistanceService = new google.maps.DistanceMatrixService();
  DistanceService.getDistanceMatrix({
    origins: gOriginsArray[k],
    destinations: gDestinationsArray[k],
    travelMode: google.maps.TravelMode.DRIVING,
    unitSystem: google.maps.UnitSystem.METRIC,
    avoidHighways: false,
    avoidTolls: false
  }, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      var results = response.rows[0].elements;
      for (var l = 0; l < results.length; l++) {
        gDistanceArray.push(results[l].distance.text);
      }
    } else if (status === google.maps.DirectionsStatus.OVER_QUERY_LIMIT) {
      setTimeout(function() {
        console.log('OVER_QUERY_LIMIT');
      }, 10000);
    } else {
      console.log(status);
      gDistanceArray.push('');
    }
  });

}
LoadBookingsArray(Records);

enter image description here

My Updated version with async/await

I have two Arrays (gOriginsArray, gDestinationsArray) which are Array of Arrays and I am storing 10 addresses in each array and I have close to 300 origins addresses and 300 destinations address stored in a sets of 10 entries. My gOriginsArray has 300 identical elements. I am running a loop and sending 10 addresses from both array to calculate the distance but my loop carries on before I get result from DistanceMatrixService and I get OVER_QUERY_LIMIT error as well.

I want to find the distance of all 300 addresses and then run LoadBookingsArray(Records) function.

for (var k = 0; k < gDestinationsArray.length; k++) {
  var DistanceService = new google.maps.DistanceMatrixService();
  DistanceService.getDistanceMatrix({
    origins: gOriginsArray[k],
    destinations: gDestinationsArray[k],
    travelMode: google.maps.TravelMode.DRIVING,
    unitSystem: google.maps.UnitSystem.METRIC,
    avoidHighways: false,
    avoidTolls: false
  }, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      var results = response.rows[0].elements;
      for (var l = 0; l < results.length; l++) {
        gDistanceArray.push(results[l].distance.text);
      }
    } else if (status === google.maps.DirectionsStatus.OVER_QUERY_LIMIT) {
      setTimeout(function() {
        console.log('OVER_QUERY_LIMIT');
      }, 10000);
    } else {
      console.log(status);
      gDistanceArray.push('');
    }
  });

}
LoadBookingsArray(Records);

enter image description here

I have two Arrays (gOriginsArray, gDestinationsArray) which are Array of Arrays and I am storing 10 addresses in each array and I have close to 300 origins addresses and 300 destinations address stored in a sets of 10 entries. My gOriginsArray has 300 identical elements. I am running a loop and sending 10 addresses from both array to calculate the distance but my loop carries on before I get result from DistanceMatrixService and I get OVER_QUERY_LIMIT error as well.

I want to find the distance of all 300 addresses and then run LoadBookingsArray(Records) function.

for (var k = 0; k < gDestinationsArray.length; k++) {
  var DistanceService = new google.maps.DistanceMatrixService();
  DistanceService.getDistanceMatrix({
    origins: gOriginsArray[k],
    destinations: gDestinationsArray[k],
    travelMode: google.maps.TravelMode.DRIVING,
    unitSystem: google.maps.UnitSystem.METRIC,
    avoidHighways: false,
    avoidTolls: false
  }, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      var results = response.rows[0].elements;
      for (var l = 0; l < results.length; l++) {
        gDistanceArray.push(results[l].distance.text);
      }
    } else if (status === google.maps.DirectionsStatus.OVER_QUERY_LIMIT) {
      setTimeout(function() {
        console.log('OVER_QUERY_LIMIT');
      }, 10000);
    } else {
      console.log(status);
      gDistanceArray.push('');
    }
  });

}
LoadBookingsArray(Records);

enter image description here

I have two Arrays (gOriginsArray, gDestinationsArray) which are Array of Arrays and I am storing 10 addresses in each array and I have close to 300 origins addresses and 300 destinations address stored in a sets of 10 entries. My gOriginsArray has 300 identical elements. I am running a loop and sending 10 addresses from both array to calculate the distance but my loop carries on before I get result from DistanceMatrixService and I get OVER_QUERY_LIMIT error as well.

I want to find the distance of all 300 addresses and then run LoadBookingsArray(Records) function.

for (var k = 0; k < gDestinationsArray.length; k++) {
  var DistanceService = new google.maps.DistanceMatrixService();
  DistanceService.getDistanceMatrix({
    origins: gOriginsArray[k],
    destinations: gDestinationsArray[k],
    travelMode: google.maps.TravelMode.DRIVING,
    unitSystem: google.maps.UnitSystem.METRIC,
    avoidHighways: false,
    avoidTolls: false
  }, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      var results = response.rows[0].elements;
      for (var l = 0; l < results.length; l++) {
        gDistanceArray.push(results[l].distance.text);
      }
    } else if (status === google.maps.DirectionsStatus.OVER_QUERY_LIMIT) {
      setTimeout(function() {
        console.log('OVER_QUERY_LIMIT');
      }, 10000);
    } else {
      console.log(status);
      gDistanceArray.push('');
    }
  });

}
LoadBookingsArray(Records);

enter image description here

My Updated version with async/await

added 1843 characters in body
Source Link
Karim Ali
  • 2.4k
  • 6
  • 25
  • 35
async function RunBookings() {
    for (var k = 0; k < gDestinationsArray.length; k++) {        
        let promise = new Promise(function(resolve, reject) {            
            var DistanceService = new google.maps.DistanceMatrixService();
            DistanceService.getDistanceMatrix({
                origins: gOriginsArray[k],
                destinations: gDestinationsArray[k],
                travelMode: google.maps.TravelMode.DRIVING,
                unitSystem: google.maps.UnitSystem.METRIC,
                avoidHighways: false,
                avoidTolls: false
            }, function(response, status) {
                if (status == google.maps.DirectionsStatus.OK) {
                    console.log(response);
                    var results = response.rows[0].elements; 
                    for (var l = 0; l < results.length; l++) {
                        gDistanceArray.push(results[l].distance.text);
                    }
                    resolve('Good promise');
                } else if (status === google.maps.DirectionsStatus.OVER_QUERY_LIMIT) {
                    console.log('OVER_QUERY_LIMIT');
                    console.log(response);
                    console.log(status);
                    reject(Error("Bad promise"));
                } else {
                    console.log('BAD');
                    console.log(response);
                    console.log(status);
                    reject(new Error("Bad promise"));
                }
            });
        });
        let result = await promise;
    }
}

I have two Arrays (gOriginsArray, gDestinationsArray) which are Array of Arrays and I am storing 10 addresses in each array and I have close to 300 origins addresses and 300 destinations address stored in a sets of 10 entries. My gOriginsArray has 300 identical elements. I am running a loop and sending 10 addresses from both array to calculate the distance but my loop carries on before I get result from DistanceMatrixService and I get OVER_QUERY_LIMIT error as well.

I have two Arrays (gOriginsArray, gDestinationsArray) which are Array of Arrays and I am storing 10 addresses in each array and I have close to 300 origins addresses and 300 destinations address stored in a sets of 10 entries. My gOriginsArray has 300 identical elements. I am running a loop and sending 10 addresses from both array to calculate the distance but my loop carries on before I get result from DistanceMatrixService and I get OVER_QUERY_LIMIT error as well.

async function RunBookings() {
    for (var k = 0; k < gDestinationsArray.length; k++) {        
        let promise = new Promise(function(resolve, reject) {            
            var DistanceService = new google.maps.DistanceMatrixService();
            DistanceService.getDistanceMatrix({
                origins: gOriginsArray[k],
                destinations: gDestinationsArray[k],
                travelMode: google.maps.TravelMode.DRIVING,
                unitSystem: google.maps.UnitSystem.METRIC,
                avoidHighways: false,
                avoidTolls: false
            }, function(response, status) {
                if (status == google.maps.DirectionsStatus.OK) {
                    console.log(response);
                    var results = response.rows[0].elements; 
                    for (var l = 0; l < results.length; l++) {
                        gDistanceArray.push(results[l].distance.text);
                    }
                    resolve('Good promise');
                } else if (status === google.maps.DirectionsStatus.OVER_QUERY_LIMIT) {
                    console.log('OVER_QUERY_LIMIT');
                    console.log(response);
                    console.log(status);
                    reject(Error("Bad promise"));
                } else {
                    console.log('BAD');
                    console.log(response);
                    console.log(status);
                    reject(new Error("Bad promise"));
                }
            });
        });
        let result = await promise;
    }
}

I have two Arrays (gOriginsArray, gDestinationsArray) which are Array of Arrays and I am storing 10 addresses in each array and I have close to 300 origins addresses and 300 destinations address stored in a sets of 10 entries. My gOriginsArray has 300 identical elements. I am running a loop and sending 10 addresses from both array to calculate the distance but my loop carries on before I get result from DistanceMatrixService and I get OVER_QUERY_LIMIT error as well.

added 45 characters in body
Source Link
Karim Ali
  • 2.4k
  • 6
  • 25
  • 35

I have two Arrays (gOriginsArray, gDestinationsArray) which are Array of Arrays and I am storing 10 addresses in each array and I have close to 300 origins addresses and 300 destinations address stored in a sets of 10 entries. My gOriginsArray has 300 identical elements. I am running a loop and sending 10 addresses from both array to calculate the distance but my loop carries on before I get result from DistanceMatrixService and I get OVER_QUERY_LIMIT error as well.

I want to find the distance of all 300 addresses and then run LoadBookingsArray(Records) function.

for (var k = 0; k < gDestinationsArray.length; k++) {
  var DistanceService = new google.maps.DistanceMatrixService();
  DistanceService.getDistanceMatrix({
    origins: gOriginsArray[k],
    destinations: gDestinationsArray[k],
    travelMode: google.maps.TravelMode.DRIVING,
    unitSystem: google.maps.UnitSystem.METRIC,
    avoidHighways: false,
    avoidTolls: false
  }, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      var results = response.rows[0].elements;
      for (var l = 0; l < results.length; l++) {
        gDistanceArray.push(results[l].distance.text);
      }
    } else if (status === google.maps.DirectionsStatus.OVER_QUERY_LIMIT) {
      setTimeout(function() {
        console.log('OVER_QUERY_LIMIT');
      }, 10000);
    } else {
      console.log(status);
      gDistanceArray.push('');
    }
  });

}
LoadBookingsArray(Records);

enter image description here

I have two Arrays (gOriginsArray, gDestinationsArray) which are Array of Arrays and I am storing 10 addresses in each array and I have close to 300 origins addresses and 300 destinations address stored in a sets of 10 entries. I am running a loop and sending 10 addresses from both array to calculate the distance but my loop carries on before I get result from DistanceMatrixService and I get OVER_QUERY_LIMIT error as well.

I want to find the distance of all 300 addresses and then run LoadBookingsArray(Records) function.

for (var k = 0; k < gDestinationsArray.length; k++) {
  var DistanceService = new google.maps.DistanceMatrixService();
  DistanceService.getDistanceMatrix({
    origins: gOriginsArray[k],
    destinations: gDestinationsArray[k],
    travelMode: google.maps.TravelMode.DRIVING,
    unitSystem: google.maps.UnitSystem.METRIC,
    avoidHighways: false,
    avoidTolls: false
  }, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      var results = response.rows[0].elements;
      for (var l = 0; l < results.length; l++) {
        gDistanceArray.push(results[l].distance.text);
      }
    } else if (status === google.maps.DirectionsStatus.OVER_QUERY_LIMIT) {
      setTimeout(function() {
        console.log('OVER_QUERY_LIMIT');
      }, 10000);
    } else {
      console.log(status);
      gDistanceArray.push('');
    }
  });

}
LoadBookingsArray(Records);

enter image description here

I have two Arrays (gOriginsArray, gDestinationsArray) which are Array of Arrays and I am storing 10 addresses in each array and I have close to 300 origins addresses and 300 destinations address stored in a sets of 10 entries. My gOriginsArray has 300 identical elements. I am running a loop and sending 10 addresses from both array to calculate the distance but my loop carries on before I get result from DistanceMatrixService and I get OVER_QUERY_LIMIT error as well.

I want to find the distance of all 300 addresses and then run LoadBookingsArray(Records) function.

for (var k = 0; k < gDestinationsArray.length; k++) {
  var DistanceService = new google.maps.DistanceMatrixService();
  DistanceService.getDistanceMatrix({
    origins: gOriginsArray[k],
    destinations: gDestinationsArray[k],
    travelMode: google.maps.TravelMode.DRIVING,
    unitSystem: google.maps.UnitSystem.METRIC,
    avoidHighways: false,
    avoidTolls: false
  }, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      var results = response.rows[0].elements;
      for (var l = 0; l < results.length; l++) {
        gDistanceArray.push(results[l].distance.text);
      }
    } else if (status === google.maps.DirectionsStatus.OVER_QUERY_LIMIT) {
      setTimeout(function() {
        console.log('OVER_QUERY_LIMIT');
      }, 10000);
    } else {
      console.log(status);
      gDistanceArray.push('');
    }
  });

}
LoadBookingsArray(Records);

enter image description here

deleted 210 characters in body
Source Link
Felix Kling
  • 810.7k
  • 176
  • 1.1k
  • 1.2k
Loading
Source Link
Karim Ali
  • 2.4k
  • 6
  • 25
  • 35
Loading