0

Why is status OVER_QUERY_LIMIT running before Status.OK? I use this code:

directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
        var response = Math.ceil(response.routes[0].legs[0].distance.value / 1000);

        stores.push({
            distance: response,
            id: item.properties.Nid,
        });

        console.log('STATUS.OK');
    } else if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT){
        console.log('OVER_QUERY_LIMIT');
    }
});

Status OVER_QUERY_LIMIT is logged before the STATUS.OK. I know that OVER_QUERY_LIMIT is running because I did to many requests.

But I can't figure how I could create a delay when OVER_QUERY_LIMIT is always running first.

Can someone explain it to me please?

Appel
  • 497
  • 5
  • 13

1 Answers1

2

The request is asynchronous. It takes more time to generate the data for a status="OK" response than it does to return the status="OVER_QUERY_LIMIT" response.

You need to handle the request that resulted in the "OVER_QUERY_LIMIT" status as is done in the related question: OVER_QUERY_LIMIT in Google Maps API v3: How do I pause/delay in Javascript to slow it down?

Community
  • 1
  • 1
geocodezip
  • 158,664
  • 13
  • 220
  • 245