Google maps 谷歌地图:DirectionService返回超过查询限制的响应

Google maps 谷歌地图:DirectionService返回超过查询限制的响应,google-maps,google-maps-api-3,Google Maps,Google Maps Api 3,我正在使用google.maps.DirectionsService获取两点之间的路线。此代码在过去8个月内有效。然而,从过去的几天开始,DirectionService路由调用返回的响应状态超过了查询限制。只有6组点,其中只有2到3个请求得到了结果,其余的都失败了。代码从过去8个月起保持不变。以下是供参考的代码片段: var directionsService = new google.maps.DirectionsService(); var

我正在使用google.maps.DirectionsService获取两点之间的路线。此代码在过去8个月内有效。然而,从过去的几天开始,DirectionService路由调用返回的响应状态超过了查询限制。只有6组点,其中只有2到3个请求得到了结果,其余的都失败了。代码从过去8个月起保持不变。以下是供参考的代码片段:

            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
                    });
                }
            }
几乎有6个这样的同时请求是向DirectionService发出的。我不能在两个请求之间设置睡眠,因为这会增加我的应用程序GUI加载时间

我也在不同的网络上尝试过相同的代码,但问题仍然存在

我绝对没有达到每天2500次的请求限制

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

任何帮助都将不胜感激

提前谢谢


Satyapal

谷歌地图API有两种配额。您正在使用客户端配额,如果您每分钟请求超过~20个(这是我观察到的)地理代码,它将阻止您

有关详细信息,请参见此处:


尝试将您的请求放入setTimeout()函数中:查询限制可能是指过去的请求离此请求太近

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

我遵循Google的API进行服务器端指导,并创建了一个PHP页面,如果
超过查询限制
作为状态返回,该页面将
休眠(0.2)
。然后我使用
$.getJSON
检索这个PHP页面,它使用几乎完全相同的数据和参数。(请按照以下步骤处理参数中的差异。)

PHP:

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时,您会将lat/lng位置作为Google LatLng对象返回,这在这里不会发生。我刚刚使用了
新的google.maps.LatLng(…,…)
将它们重新构建到对象中。

可能希望从搜索堆栈溢出开始,并看到人们对几乎相同问题的回答:我仍然无法解决这个问题。有人对此有答案吗?请帮助。在处理了10条路径后,我超过了查询限制。有人能告诉我答案吗?
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
    };
});