title: SetTimeout on Directionservice route in google map javascript API
body: <p>I am using Directionservice of Google Map JavaScript API. Actually I am not able to display more than 10 routes in my map. If I am trying to display more than 10 routes then it is throwing the OVER_QUERY_LIMIT error. 
  Even though after setting the setTimeout function not able to display all the routes. I am using only 20 routes to display on the map and not able to display those 20 routes. But if I use the setInterval function then am able to see the all the routes but not able to stop the interval with clearInterval function too so it is going in infinite loop.
  <div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function buildRoute(from, to, fromId, toId, index) {
    setTimeout(function() {
      var directionsService = new google.maps.DirectionsService();
      var color = setColor(index);
      var rendererOptions = {
        map: myMap,
        suppressMarkers: true,
        polylineOptions: {
          strokeColor: color
        }
      };
  
      var directionsRequest = {
        origin: from,
        destination: to,
        travelMode: getTraveMode(),
        unitSystem: google.maps.UnitSystem.METRIC
      };
  
      directionsService.route(directionsRequest, function(response, status) {
  
        count = count + 1;
        console.log(count + " " + fromId + " " + toId);
        if (status != google.maps.DirectionsStatus.OK)
          console.log(status);
        if (status == google.maps.DirectionsStatus.OK) {
          counter = counter + 1;
          var directionsDisplay = new google.maps.DirectionsRenderer(
            rendererOptions);
          directionsDisplay.setDirections(response);
          custimiseDriection(response, fromId, toId, color);
          if (counter == totRoutes) {
            // clearInterval();
            displayTimeandDistance();
          }
        }
      })
    }, 1000)
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>The SetTimeout function is used at different places in the below code as like below but not able to overcome the OVER_QUERY_LIMIT.</p>
  
  <ol>
  <li>setTimeOut(buildRoute(from, to, fromId, toId, index), 1000)</li>
  <li>Just enclosed the directionservice.route function in setTimeout function</li>
  <li>Just enclosed the callback function code of directionservice.route is the setTimeout function.</li>
  </ol>
  
  <p>Here is the screen shot of OVER_QUERY_LIMIT errors in chrome console.
  <a href="http://i.stack.imgur.com/MrewI.png" rel="nofollow">OVER QUERY LIMIT Error</a></p>