Google maps 谷歌地图API超过每秒查询限制
我正在使用谷歌地图API在地图上显示大约50个位置。我正在使用客户端地理编码。我使用window.setTimeout控制应用程序每秒发送的地理代码请求数。如果我每秒发送超过1个请求,我将得到一个超过查询限制的响应 问题:这个限制不是应该是每秒10次查询吗?如果是,那么我会做错什么?如果否,那么业务API是否有更大的每秒查询限制?Google maps 谷歌地图API超过每秒查询限制,google-maps,google-maps-api-3,Google Maps,Google Maps Api 3,我正在使用谷歌地图API在地图上显示大约50个位置。我正在使用客户端地理编码。我使用window.setTimeout控制应用程序每秒发送的地理代码请求数。如果我每秒发送超过1个请求,我将得到一个超过查询限制的响应 问题:这个限制不是应该是每秒10次查询吗?如果是,那么我会做错什么?如果否,那么业务API是否有更大的每秒查询限制? 请注意,我们的应用程序不会达到每天25000个查询。地理编码器有配额和费率限制。根据经验,您可以在不超过查询限制的情况下对10个位置进行地理编码(实际数量可能取决于服
请注意,我们的应用程序不会达到每天25000个查询。地理编码器有配额和费率限制。根据经验,您可以在不超过查询限制的情况下对10个位置进行地理编码(实际数量可能取决于服务器负载)。最好的解决方案是在超过查询限制错误时延迟,然后重试。见以下类似帖子:
这种方法是不正确的,因为谷歌服务器超载。 有关更多信息,请参阅
顺便说一句,如果你想继续,你可以在这里找到一个代码,让你可以加载多个标记ajax源于谷歌地图,避免超过查询限制的错误 我已经在我的onw服务器上进行了测试,它运行正常:
var lost_addresses = [];
geocode_count = 0;
resNumber = 0;
map = new GMaps({
div: '#gmap_marker',
lat: 43.921493,
lng: 12.337646,
});
function loadMarkerTimeout(timeout) {
setTimeout(loadMarker, timeout)
}
function loadMarker() {
map.setZoom(6);
$.ajax({
url: [Insert here your URL] ,
type:'POST',
data: {
"action": "loadMarker"
},
success:function(result){
/***************************
* Assuming your ajax call
* return something like:
* array(
* 'status' => 'success',
* 'results'=> $resultsArray
* );
**************************/
var res=JSON.parse(result);
if(res.status == 'success') {
resNumber = res.results.length;
//Call the geoCoder function
getGeoCodeFor(map, res.results);
}
}//success
});//ajax
};//loadMarker()
$().ready(function(e) {
loadMarker();
});
//Geocoder function
function getGeoCodeFor(maps, addresses) {
$.each(addresses, function(i,e){
GMaps.geocode({
address: e.address,
callback: function(results, status) {
geocode_count++;
if (status == 'OK') {
//if the element is alreay in the array, remove it
lost_addresses = jQuery.grep(lost_addresses, function(value) {
return value != e;
});
latlng = results[0].geometry.location;
map.addMarker({
lat: latlng.lat(),
lng: latlng.lng(),
title: 'MyNewMarker',
});//addMarker
} else if (status == 'ZERO_RESULTS') {
//alert('Sorry, no results found');
} else if(status == 'OVER_QUERY_LIMIT') {
//if the element is not in the losts_addresses array, add it!
if( jQuery.inArray(e,lost_addresses) == -1) {
lost_addresses.push(e);
}
}
if(geocode_count == addresses.length) {
//set counter == 0 so it wont's stop next round
geocode_count = 0;
setTimeout(function() {
getGeoCodeFor(maps, lost_addresses);
}, 2500);
}
}//callback
});//GeoCode
});//each
};//getGeoCodeFor()
例如:
map=新的gmap({
部门:“#gmap#U标记”,
拉脱维亚:43.921493,
液化天然气:12.337646,
});
var jsonData={
“状态”:“成功”,
“结果”:[
{
“客户ID”:1,
“地址”:“米兰(密苏里州)Via Italia 43”,
“customerName”:“MyAwesomeCustomer1”
},
{
“客户ID”:2,
“地址”:“通过罗马10号,罗马(RM)”,
“customerName”:“MyAwesomeCustomer2”
}
]
};
函数loadMarkerTimeout(超时){
setTimeout(加载标记,超时)
}
函数loadMarker(){
map.setZoom(6);
$.ajax({
url:“/echo/html/”,
类型:“POST”,
资料来源:jsonData,
cache:false,
成功:功能(结果){
var res=JSON.parse(结果);
如果(res.status='success'){
resNumber=res.results.length;
//调用geoCoder函数
getGeoCodeFor(地图、结果);
}
}//成功
});//ajax
};//loadMarker()
$().ready(功能(e){
loadMarker();
});
//地理编码器功能
函数getGeoCodeFor(地图、地址){
$.each(地址,函数(i,e){
地理编码({
地址:e.address,
回调:函数(结果、状态){
地理编码_计数++;
console.log('Id:'+e.customerId+'| Status:'+Status);
如果(状态=='OK'){
//如果该元素一直在数组中,请将其删除
丢失的地址=jQuery.grep(丢失的地址,函数(值){
返回值!=e;
});
latlng=results[0]。geometry.location;
map.addMarker({
lat:latlng.lat(),
lng:latlng.lng(),
标题:e.客户名称,
});//添加标记
}else if(状态=‘零结果’){
//警报(“抱歉,未找到结果”);
}else if(状态=‘超过查询限制’){
//如果元素不在losts_addresses数组中,请添加它!
if(jQuery.inArray(e,丢失的_地址)=-1){
丢失_地址。推送(e);
}
}
if(地理编码\计数==地址.长度){
//设置计数器==0,以便下一轮不会停止
地理编码_计数=0;
setTimeout(函数(){
getGeoCodeFor(地图、丢失的地址);
}, 2500);
}
}//回拨
});//地理编码
});//每个
};//getGeoCodeFor()
#gmap#U标记{
最小高度:250px;
身高:100%;
宽度:100%;
位置:相对位置;
溢出:隐藏;
}
代替客户端地理编码
geocoder.geocode({
'address': your_address
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var geo_data = results[0];
// your code ...
}
})
我将转到服务器端地理编码API
var apikey = YOUR_API_KEY;
var query = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + address + '&key=' + apikey;
$.getJSON(query, function (data) {
if (data.status === 'OK') {
var geo_data = data.results[0];
}
})
谢谢你。我确实尝试使用window.setTimeout延迟它,但它只在延迟1秒的情况下工作。现在,我更改了代码,以便发出地理代码请求,直到得到一个超过查询限制的响应。之后,我暂停3秒钟,然后重复。这种策略似乎能在26秒内(而不是50秒)解决50个请求。如果有更好的策略,我洗耳恭听。