2012-06-20 66 views
2

我正在使用google.maps.DirectionsService获取两点之间的路线。该代码在过去的8个月内运行。但是,从过去的几天,DirectionService路由调用正在返回OVER_QUERY_LIMIT响应状态。只有6组点,其中只有2或3个请求得到结果,其余都失败。代码与过去8个月保持一致。以下是供参考的代码片段:Google地图:DirectionService返回OVER_QUERY_LIMIT回复

  var directionsService = new google.maps.DirectionsService(); 
      var request = {      
        origin:originLatlng, //This is of type : google.maps.LatLng 
        destination:destLatlng, 
        travelMode: google.maps.DirectionsTravelMode.DRIVING, 
        provideRouteAlternatives: true 
      }; 

      directionsService.route(request, function(result, status) { 
       if (status == google.maps.DirectionsStatus.OK) { 

        polyline = new google.maps.Polyline({ 
         path: result.routes[0].overview_path, 
         strokeColor: color1, 
         strokeOpacity: 0.8, 
         strokeWeight: 5, 
         geodesic: true 
        }); 
       } 
      } 

向DirectionService发出几乎6个这样的同时请求。我无法在请求之间进行睡眠,因为它会增加我的应用程序GUI加载时间。

我已经尝试了来自不同网络的相同代码,仍然存在问题。

我绝对没有接近达到每日2500的要求限制。

这里有什么问题?请为此提出解决方案。

任何帮助将不胜感激。

在此先感谢

Satyapal

+0

可能要从搜索Stack Overflow开始,看到人们对几乎相同的问题的回答:http://stackoverflow.com/search?q=over_query_limit – andresf

+0

我仍然无法解决此问题。有没有人有这个答案?请帮忙。 – user1469358

+0

10个路径得到处理后,我得到over_query_limit。有人可以解决它吗? –

回答

0

尝试把你的要求的setTimeout()函数中:在query_limit也可以从附近的这一个被称为过去的请求。

setTimeout(function(){ 
    directionsService.route(request,function(result, status) { 
     if (status == google.maps.DirectionsStatus.OK) 
      {[...your code...]} 
     else alert(status); 
    }); 
},1000); 
0

我跟谷歌的服务器端API的方向,创造了将sleep(0.2)如果OVER_QUERY_LIMIT返回的状态的PHP页面。然后我用$.getJSON来检索这个PHP页面,它使用差不多的完全相同的数据和参数。 (按照Google's directions处理参数中的差异。)

PHP:

$params = http_build_query($_GET); 
$url = "http://maps.googleapis.com/maps/api/directions/json?sensor=false&" . $params; 
$json = file_get_contents($url); 
$status = json_decode($json)->status; 

// check for over_query_limit status 
while ($status=="OVER_QUERY_LIMIT") { 
    sleep(0.2); // seconds 
    $json = file_get_contents($url); 
    $status = json_decode($json)->status; 
} 

header('application/json'); 
echo $json; 

的jQuery:

request = { // construct route request object 
    origin: start_address, 
    destination: end_address, 
    waypoints: addresses.join('|'), 
    avoid: 'tolls' 
}; 

$.getJSON('directions-lookup.php', request, function(response) { 
    //console.log(response); 
    var status = response.status; 
    if (status==google.maps.DirectionsStatus.OK) { 
     // do things here 
    }; 
}); 

东西我注意到的是,当你使用JavaScript API方向,您会像Google LatLng对象那样获取像lat/lng位置这样的内容,这在这里不会发生。我只是使用new google.maps.LatLng(..., ...)将它们重新构建到对象中。