19

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.

Bryan Weaver
  • 4,455
  • 1
  • 29
  • 39
user1283452
  • 191
  • 1
  • 1
  • 3
  • 2
    We got the same OVER_QUERY_LIMIT error for people on 3G, while when they were using WiFi it was working correctly. The problem with 3G is that from what I read, most of the time NAT is used, so all users from a same provider may end up having the same public address and thus this IP address would easily exceed the limitation. – user276648 Jan 29 '14 at 00:23

6 Answers6

34

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;
}
Bryan Weaver
  • 4,455
  • 1
  • 29
  • 39
  • 1
    Thanks for the js code. Setting the delay with a retry works great. – steampowered Jun 20 '12 at 04:52
  • Something about the C# solution looks off to me. It returns an XElement to the caller. However, if `GetGeocodingSearchResults()` is called a second time the result is ignored. And if you changed the line to read `return GetGeocodingSearchResults(address);` you could overflow the stack. An alternative solution would be to run this code in a loop until success or a predetermined number of failures. It should also be noted that while this will throttle the request rate, you still need to worry about the daily limit. – dana Jul 13 '12 at 20:44
  • I used the same solution, but the alert keeps on popping up on account of the browser receiving generating the alert from the API. – Carl Carlson May 19 '14 at 21:02
  • setting delay works, but it increase the loading map time :-( – Trimantra Software Solution May 16 '17 at 10:23
4

We had this problem as well and the solution was to ditch google's API. If all you need is geocoding there are numerous alternatives that are equally as effective without the limitations. We chose the mapquest API. It has been faster and more reliable with no cap on geocoding calls plus I really like their API for batching together geocoding requests into a single call.

If there are other features you require, obviously you have to take those into consideration, but in the case of a single feature, using the biggest API on the block is not necessarily the best choice.

developer.mapquest.com

NSProgrammer
  • 2,387
  • 1
  • 24
  • 27
  • My first inclination is to ditch Google Maps for Mapquest after reading this. But how long until Mapquest implements a rate limiter too? Switching costs are significant. – steampowered Jun 20 '12 at 04:23
  • Actually, sad to say, mapquest has already implemented a rate limit. Double that of google's, but it's there. An update to my answer is to fork my code (though in a nice encapsulated way) such that on iOS 5 I use Apple's geocoding API and for all older iOS versions I use mapquest. This has been very effective since the percent of devices using older iOS versions is falling every day we rarely hit Mapquests daily limit anymore (though it does happen so we have a graceful fallback). Of course this only helps for iOS. Other platforms still need a solution :( – NSProgrammer Jun 20 '12 at 13:26
3

Google, Bing, MapQuest, and Yahoo! Maps (is this API still around?) are extremely powerful tools. They have a lot of horsepower that they put behind interpreting the address you provide and doing everything possible to make it into a properly formatted address for geocoding. To a certain degree they are free. They have volume limits and pretty strict Terms Of Service (TOS) that might be a factor if you start using their service commercially and especially if you integrate it into another product.

Keep in mind that all of them do "address approximation" NOT address verification. They will be able to tell you approximately where an address would lie on a certain street IF the address exists. They cannot tell you that the address you are looking for exists. One way to verify this is to look at your own address in Google Maps. Zoom all the way in to street view and you'll see that they state "address is approximate" even though they may have the location pinpointed exactly. They just don't have the master list of addresses to compare and know which addresses are real. For that, you will need some sort of address verification.

Address verification standardizes and cleans a given address in much the same way as the free mapping services but it also compares the addresses to the USPS database of deliverable addresses to confirm if the address really exists. The confirmed address can then be geocoded with improved accuracy.

There are a lot of good address verification services out there. In the interest of full disclosure, I'm the founder of one--SmartyStreets.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Jonathan Oliver
  • 5,207
  • 32
  • 31
2

You can also do geocoding on the client side. Here's an article comparing the approach of doing something client side and something server site.

Mano Marks
  • 8,761
  • 3
  • 27
  • 28
1

Google also returns this same response if no address matches were found. It does not necessarily mean you've exceeded the quota. In any case you'll be better off catching the exception and implementing a rescue around it.

svilenv
  • 1,484
  • 1
  • 11
  • 13
  • 1
    This is not true for V3. You get a valid response with zero results. No downvote since you may of been commenting about V2 and I don't know what the result was then. – Kijana Woodard Sep 11 '15 at 12:55
1

Same problem as user276648 here. Solved it by adding the API key and changing http to https.

jhondel
  • 76
  • 1
  • 6