use*_*452 18 google-maps geocoding
我正在服务器端使用地理编码API来翻译latlng中的地址.我面临OVER_QUERY_LIMIT状态,即使: - 服务器没有超过2500限制(这一天只有几个请求) - 它没有同时做很多请求(一次只有一个请求)
怎么可能?第二天地理编码运行良好,但我担心我的应用程序长期正常工作.
提前致谢.
Bry*_*ver 34
这就是我过去处理这个问题的方法.我检查结果状态,如果我超过限制错误,我会在稍微延迟后再次尝试.
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);
}
});
}
Run Code Online (Sandbox Code Playgroud)
更新:哎呀,不小心掩盖了服务器端部分.这是一个C#版本:
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;
}
Run Code Online (Sandbox Code Playgroud)
我们也遇到了这个问题,解决方案是放弃谷歌的 API。如果您需要的只是地理编码,那么有许多替代方案同样有效且没有任何限制。我们选择了mapquest API。它更快、更可靠,对地理编码调用没有限制,而且我真的很喜欢他们的 API,可以将地理编码请求批量合并到一个调用中。
如果您还需要其他功能,显然您必须考虑这些功能,但在单个功能的情况下,使用块上最大的 API 不一定是最佳选择。
开发者.mapquest.com
| 归档时间: |
|
| 查看次数: |
42866 次 |
| 最近记录: |