Question

Here I create a code with google map, google places, routebox library to show directions beetween two locations and to show object near direction (10,20,30 miles) with google places.

Here is the demo and code: http://jsbin.com/EVEWOta/55 but after trying "10mi" distance, from Madrid to Moscow I get this errors:

    ...
    ...
    ...


   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 

This code:

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

This code stop searching in boxes[14]. Why?

I pt in code setTimeot with 10s before call next box?

What is the really problem here?

Was it helpful?

Solution

You must wrap the call of findPlaces into a function, otherwise the function will be called immediately and not with the desired delay:

setTimeout(function(){findPlaces(boxes,searchIndex);},10000);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top