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;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…