本文介绍了设置超时以避免 over_query-limit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 googlemaps 地理编码器检索地址..但我只得到几个地址..因为我看到我的 javascript 在 10 个地址后无法检索..下面是我的代码
i am trying to retrieve addresses using the googlemaps geocoder..but iam getting only few addresses ..as i see my javascript is failing to retrieve after 10 addresses..below is my code
function fetchData(lat,lng,type){
$('#placedata').empty();
myLatlng = new google.maps.LatLng(parseFloat(lat), parseFloat(lng));
map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: myLatlng,
zoom: 10});
var request = {location: myLatlng,radius: 50000,types: [type]};
var service = new google.maps.places.PlacesService(map);
service.search(request, callback);
}
function callback(results, status) {
for (var i = 0; i < results.length; i++) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
createMarker(results[i]);
}
}
}
function createMarker(place) {
place.geometry.location});
var request = {reference: place.reference,};
service = new google.maps.places.PlacesService(map);
service.getDetails(request, detailsDisplay);
function detailsDisplay(details, status) {
$('#placedata').append('<tr><td><a href='+details.url+'>'+details.name+'</a></td></tr>');
}
}
正如我看到的很多人有同样的问题..有没有办法或使用 setTimeout 函数并延迟请求,以便我获得至少 20 个地址..任何帮助将不胜感激..谢谢
As i see many have same problem ..is there a way or using setTimeout function and delay the request so i get get atleast 20 addresses..Any help would be appreciated..thankyou
推荐答案
解决方案是使用setTimeout
来防止OVER_QUERY_LIMIT
:
The solution is use setTimeout
to prevent OVER_QUERY_LIMIT
:
function createMarker(place) {
//var placeLoc = place.geometry.location;
//var marker = new google.maps.Marker({map: map,zIndex: 100,position: place.geometry.location});
var request = {
reference : place.reference,
};
service = new google.maps.places.PlacesService(map);
service.getDetails(request, function(details, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
$('#placedata').append('<tr><td><a href='+details.url+'>' + details.name + '</a></td></tr>');
} else if (status === google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
setTimeout(function() {
createMarker(place);
}, 200);
}
});
}
这篇关于设置超时以避免 over_query-limit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!