在查询限制中显示过多的递归

时间:2014-01-16 09:29:11

标签: google-maps google-maps-api-3

当google map api返回状态超过查询限制时显示太多递归。我们如何解决它。

function calcRoute(origi,desti,planid,segno,routeType,imageUrl) {
 var request = {
 origin: origi,
 destination: desti,
 travelMode: routeType
 };
 directionsService.route(request, function(response, status) {
 //alert("status is "+status);
 if (status == google.maps.DirectionsStatus.OK) {
 computeTotalDistance( response,planid,segno,routeType,origi,desti,imageUrl);
 //alert("origi "+origi+" desti "+desti);
}
 else if(status == google.maps.DirectionsStatus.OVER_QUERY_LIMIT){
 // usleep(10000);
 wait = true;
 setTimeout("wait = true", 200000);
 calcRoute(origi,desti,planid,segno,routeType,imageUrl);
 //calcRoute(origi,desti,planid,segno,routeType);
 }

 });
}
 showing too much reursion

1 个答案:

答案 0 :(得分:0)

setTimeout()setTimeout()没有帮助,因为"wait = true""wait = true"放入队列并返回。 calcRoute()将在200秒后执行,但会立即调用setTimeout(function() { calcRoute(origi,desti,planid,segno,routeType,imageUrl); }, 2000);

如果您想在延迟使用一段时间后调用calcRoute():

{{1}}