超过查询限制和最大调用堆栈大小

Over query limit and maximum call stack size

本文关键字:调用 堆栈 查询      更新时间:2023-09-26

在这里,我用谷歌地图、谷歌位置、routebox库创建了一个代码,以显示两个位置之间的方向,并用谷歌位置显示方向附近(10,20,30英里)的对象。

以下是演示和代码:http://jsbin.com/EVEWOta/55但在尝试了从马德里到莫斯科的"10米"距离后,我出现了以下错误:

    ...
    ...
    ...

   OVER_QUERY_LIMIT 55:121
    199
    OVER_QUERY_LIMIT 55:121
    OK 55:121
    1268
    OVER_QUERY_LIMIT 55:121
    3
    OVER_QUERY_LIMIT
    Uncaught RangeError: Maximum call stack size exceeded 

此代码:

service.nearbySearch(request, function (results, status) {
    console.log(status);
    if (status == 'OVER_QUERY_LIMIT') {
        setTimeout(findPlaces(boxes,searchIndex),10000);
    }else{
        document.getElementById('side_bar').innerHTML += "bounds["+searchIndex+"] returns "+results.length+" results<br>";
        for (var i = 0, result; result = results[i]; i++) {
            var marker = createMarker(result);
        }
        if (++searchIndex < boxes.length) 
            setTimeout(findPlaces(boxes,searchIndex),10000);
    }
  });

此代码停止在方框[14]中搜索。为什么?

在调用下一个框之前,我用10s输入代码setTimeot

这里真正的问题是什么?

您必须将findPlaces的调用封装到一个函数中,否则该函数将立即被调用,而不会有所需的延迟:

setTimeout(function(){findPlaces(boxes,searchIndex);},10000);