当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
答案 0 :(得分:0)
setTimeout()
对setTimeout()
没有帮助,因为"wait = true"
将"wait = true"
放入队列并返回。 calcRoute()
将在200秒后执行,但会立即调用setTimeout(function() {
calcRoute(origi,desti,planid,segno,routeType,imageUrl);
}, 2000);
。
如果您想在延迟使用一段时间后调用calcRoute():
{{1}}