title: Google Map Direction request failed due to OVER_QUERY_LIMIT - Pause JavaScript function or PHP code
body: <p>I am getting OVER_QUERY_LIMIT when sending several request for direction service. I know that it is a well-known issue and there are several solutions to delay the request sent but I am not able to do it beacause my request are sent in a php for loop.Please help !!!</p>
  
  <p>Here is part of my php code (the code is working fine but at some point in time I get the OVER_QUERY_LIMIT error:</p>
  
  <pre><code> for($i=0;$i&lt;count($PlanningArray);$i++){
  
   echo"script&gt;
  
  initMap('$Userlocation','$ActLocation1','$ActLocation2','$DivMapID'
  
  &lt;/script&gt; "
  
  }
  </code></pre>
  
  <p>Here is the function :</p>
  
  <pre><code>function initMap(Userloc,Actloc1,Actloc2,i) {
  
  
      var renderOptions = {draggable:true};
  
      var directionsDisplay = new google.maps.DirectionsRenderer(renderOptions);
      var directionsService = new google.maps.DirectionsService;
  
      var mapOptions = {
          zoom: 11,
          center: {lat:-20.239340, lng:57.574604}
      };
  
      var map = new google.maps.Map(document.getElementById('map' + i), mapOptions);
  
      directionsDisplay.setMap(map);
  
      var items = [Actloc1,Actloc2];
  
      var  destination;
  
      if(Actloc2 == ''){
  
          destination = Actloc1;
      }
  
      else {
  
          destination = Actloc2;
      }
  
      var waypoints = [];
  
      for (var j = 0; j &lt; items.length; j++) {
  
          var address = items[j];
  
          if (address !== '') {
              waypoints.push({
                  location: address,
                  stopover: true
              });
          }
      }
  
      directionsService.route({
  
          origin: Userloc,
          destination: destination,
          travelMode: 'DRIVING',
          waypoints: waypoints
  
      }, function(response, status) {
          if (status === 'OK') {
              directionsDisplay.setDirections(response);
          } else {
              window.alert('Directions request failed due to ' + status);
          }
      });
  
  }
  </code></pre>
  
  <p>How can I pause the php code or the javascript function ?</p>