Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

google maps - Geocoding api over query limit

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...