Javascript 设置超时以避免超过查询限制

Javascript 设置超时以避免超过查询限制,javascript,google-maps-api-3,google-geocoder,Javascript,Google Maps Api 3,Google Geocoder,我正在尝试使用谷歌地图地理编码器检索地址。但是我只得到了几个地址。因为我看到我的javascript在10个地址之后检索不到地址。下面是我的代码 function fetchData(lat,lng,type){ $('#placedata').empty(); myLatlng = new google.maps.LatLng(parseFloat(lat), parseFloat(lng)); map = new google.maps.Map(documen

我正在尝试使用谷歌地图地理编码器检索地址。但是我只得到了几个地址。因为我看到我的javascript在10个地址之后检索不到地址。下面是我的代码

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>');

    }

}
函数获取数据(lat、lng、类型){
$('#placedata').empty();
myLatlng=new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
map=new google.maps.map(document.getElementById('map'){
mapTypeId:google.maps.mapTypeId.ROADMAP,
中心:myLatlng,
缩放:10});
var请求={位置:myLatlng,半径:50000,类型:[type]};
var service=newgoogle.maps.places.PlacesService(地图);
服务搜索(请求、回调);
}
函数回调(结果、状态){
对于(var i=0;i

正如我所见,许多人都有同样的问题。是否有办法或使用setTimeout函数延迟请求,以便我至少获得20个地址。任何帮助都将不胜感激。谢谢。解决方法是使用
setTimeout
来防止
超过查询限制

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);
        }
    });
}
函数createMarker(位置){
//var placeLoc=place.geometry.location;
//var marker=new google.maps.marker({map:map,zIndex:100,position:place.geometry.location});
var请求={
参考:place.reference,
};
服务=新的google.maps.places.PlacesService(地图);
service.getDetails(请求、函数(详细信息、状态){
if(status==google.maps.places.PlacesServiceStatus.OK){
$('#placedata')。追加('');
}else if(status==google.maps.GeocoderStatus.OVER\u QUERY\u LIMIT){
setTimeout(函数(){
创建标记(位置);
}, 200);
}
});
}

解决方案是使用
设置超时
来防止
超过查询限制

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);
        }
    });
}
函数createMarker(位置){
//var placeLoc=place.geometry.location;
//var marker=new google.maps.marker({map:map,zIndex:100,position:place.geometry.location});
var请求={
参考:place.reference,
};
服务=新的google.maps.places.PlacesService(地图);
service.getDetails(请求、函数(详细信息、状态){
if(status==google.maps.places.PlacesServiceStatus.OK){
$('#placedata')。追加('');
}else if(status==google.maps.GeocoderStatus.OVER\u QUERY\u LIMIT){
setTimeout(函数(){
创建标记(位置);
}, 200);
}
});
}

我有解决这个问题的办法

试试这个

if(pagination.hasNextPage){
pagination.nextPage();
}

if(pagination.b == null){
createMarker(place);
}

//不需要设置超时。试试这个。这将对您有所帮助。

我有解决办法

试试这个

if(pagination.hasNextPage){
pagination.nextPage();
}

if(pagination.b == null){
createMarker(place);
}

//不需要设置超时。试试这个。这将对您有所帮助。

超过查询限制
是指网页超过其请求配额,根据地图API库为25.000。当你得到第十张唱片时,可能会发生一些错误。您是否在
callback()
函数中检查了
status
?警报语句给出了所有20个结果..如何检查akert的状态(ok);当我反复单击时,我得到20个结果OK,但此警报在哪里?要检查一切是否正常,您需要检查回调返回
google.maps.places.PlacesServiceStatus.ok
中的所有20个
status
。很抱歉,我没有收到您的消息…得到20个结果,但无法在第一次运行时显示…当网页超过其请求配额时,我只能显示10个
OVER\u QUERY\u LIMIT
,根据Maps API库,为25.000。当你得到第十张唱片时,可能会发生一些错误。您是否在
callback()
函数中检查了
status
?警报语句给出了所有20个结果..如何检查akert的状态(ok);当我反复单击时,我得到20个结果OK,但此警报在哪里?检查一切是否正常,您需要检查回调返回中的所有20
状态
google.maps.places.PlacesServiceStatus.OK
。很抱歉,我没有收到您的消息…获得20个结果,但无法在第一次运行时显示…我只能显示10hi..如果结果超过20时出现问题..我可以获得结果,但无法显示超过20Hi..显示所有结果时出现问题..获得60个结果,但使用上述超时功能只能显示20个结果.嗨..如果结果超过20时出现问题..同样,我可以获得结果,但无法显示超过20Hi..显示所有结果时出现问题..获得60个结果,但能够使用上述超时功能仅显示20个结果。是否要解释什么是heck分页以及此变量的来源?原来的帖子没有,因为它提到了它。分页是Google Map Places服务Api服务中的回调函数。nearbySearch(请求、函数(结果、状态、分页){想解释一下什么是heck分页以及这个变量是从哪里来的吗?原始的post和none,因为它提到了它。分页是Google Map Places服务Api服务中的回调函数。nearbySearch(请求、函数(结果、状态、分页){