2016-12-17 4 views
0

方向サービスのリクエストを複数送信するとOVER_QUERY_LIMITになります。私はそれがよく知られている問題であり、送信された要求を遅らせるためのいくつかの解決策があることを知っていますが、私の要求はループのためにPHPで送られてくるのでできません。ここでGoogle Map OVER_QUERY_LIMITにより方向のリクエストが失敗しました - JavaScriptの機能またはPHPコードを一時停止します

for($i=0;$i<count($PlanningArray);$i++){ 

echo"script> 

initMap('$Userlocation','$ActLocation1','$ActLocation2','$DivMapID' 

</script> " 

} 

が関数である:

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

} 

どのようにここで

は(コードが正常に動作しているが、ある時点で私はOVER_QUERY_LIMITエラーを取得する私のPHPコードの一部です。

答えて

0

私はあなたのソースをテストすることはできませんが、これは解決策だと思われます 1秒以上待って、試してみてください...

 if (stripos($ret,"OVER_QUERY_LIMIT")) 
      { 
       echo "<font color=red>OVER_QUERY_LIMIT waiting for 1 sec</font>"; 

       ob_flush(); 
       flush(); 
       sleep(1); 

       ... 
      } 
+0

$ retは何ですか? –

+0

$ retはクエリからの戻り値です。したがって、 "OVER_QUERY_LIMIT"へのequlであることを確認できます –

関連する問題