Google-maps – Geocoding api over query limit

geocodinggoogle-maps

I'm using the geocoding API on the server side to translate addresses in latlng.
I faced a OVER_QUERY_LIMIT status even though :
– the server didn't exceed the 2500 limitation (just a few request on this day)
– it didn't do many requests simultaneously (just one single request at a time)

how is that possible ? the next day the geocoding was working well but i'm concerned about my application working correctly in the long run.

Thanks in advance.

Best Solution

This is how I have handled this issue in the past. I check the result status and if I get and over the limit error I try it again after a slight delay.

function Geocode(address) {
    geocoder.geocode({
        'address': address
    }, function(results, status) {
        if (status === google.maps.GeocoderStatus.OK) {
            var result = results[0].geometry.location;
            var marker = new google.maps.Marker({
                position: result,
                map: map
            });
        } else if (status === google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {    
            setTimeout(function() {
                Geocode(address);
            }, 200);
        } else {
            alert("Geocode was not successful for the following reason:" 
                  + status);
        }
    });
}

Update: whoops, accidentally glossed over the server side part. Here is a C# version:

public XElement GetGeocodingSearchResults(string address)
{
    var url = String.Format(
         "https://maps.google.com/maps/api/geocode/xml?address={0}&sensor=false",
          Uri.EscapeDataString(address)); 

    var results = XElement.Load(url); 

    // Check the status
    var status = results.Element("status").Value;

    if(status == "OVER_QUERY_LIMIT")
    {
        Thread.Sleep(200);
        GetGeocodingSearchResults(address);
    }else if(status != "OK" && status != "ZERO_RESULTS")
    {
        // Whoops, something else was wrong with the request...     
    }

    return results;
}
Related Question