Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何处理超限查询_Javascript_Google Maps - Fatal编程技术网

Javascript 如何处理超限查询

Javascript 如何处理超限查询,javascript,google-maps,Javascript,Google Maps,我正在使用谷歌地图绘制存储在数据库中的各个位置之间的路径 当通过15个地质点(任何超过10个点)时,我的状态为超过极限 我知道,当我们每秒通过10个以上的地质点时,我们需要给出几毫秒的时间间隔 我的问题是怎么做..在哪里添加sleep()或setTimeout()或任何其他延时代码 我已经尝试了所有的,最大的所有可能性,但是失败了。因为他们只是说在请求之间给一些时间间隔,但是如何做到呢 代码段: var markers = [ {

我正在使用谷歌地图绘制存储在数据库中的各个位置之间的路径

当通过15个地质点(任何超过10个点)时,我的状态为超过极限

我知道,当我们每秒通过10个以上的地质点时,我们需要给出几毫秒的时间间隔

我的问题是怎么做..在哪里添加sleep()或setTimeout()或任何其他延时代码

我已经尝试了所有的,最大的所有可能性,但是失败了。因为他们只是说在请求之间给一些时间间隔,但是如何做到呢

代码段:

    var markers = [
                        {
                            "title": 'abc',
                            "lat": '17.5061925',
                            "lng": '78.5049901',
                            "description": '1'
                        },                  


                        {
                            "title": 'abc',
                            "lat": '17.50165',
                            "lng": '78.5139204',
                            "description": '2'
                        },
                        .
                        .
                        .
                        .
                        .
                        {
                            "title": 'abc',
                            "lat": '17.4166067',
                            "lng": '78.4853992',
                            "description": '15'
                        }

         ];


    var map;

    var mapOptions = {
        center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
        zoom: 15    ,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var path = new google.maps.MVCArray();
    var service = new google.maps.DirectionsService();

    var infoWindow = new google.maps.InfoWindow();
    var map = new google.maps.Map(document.getElementById("map"), mapOptions);

    var poly = new google.maps.Polyline({
        map: map,
        strokeColor: '#000000'
    });

    var lat_lng = new Array();

    for (var i = 0; i <= markers.length-1; i++)
    {
           var src = new google.maps.LatLng(markers[i].lat, markers[i].lng);
           var des = new google.maps.LatLng(markers[i+1].lat, markers[i+1].lng);

            poly.setPath(path);
            service.route({
                origin: src,
                destination: des,
                travelMode: google.maps.DirectionsTravelMode.DRIVING
            }, 
           function (result, status)
           {
                if (status == google.maps.DirectionsStatus.OK)
                {
  for (var i = 0, len = result.routes[0].overview_path.length;
       i < len; i++) 
                    {
                        path.push(result.routes[0].overview_path[i]);

                    }
                 } 
                 else{

                     if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT)
                     {      
                          document.getElementById('status').innerHTML +="request failed:"+status+"<br>";
                     }                                    

            } 
         });

    }
  });
var标记=[
{
“标题”:“abc”,
“lat”:“17.1925”,
“液化天然气”:“78.5049901”,
“说明”:“1”
},                  
{
“标题”:“abc”,
“lat”:“17.50165”,
“液化天然气”:“78.5139204”,
“说明”:“2”
},
.
.
.
.
.
{
“标题”:“abc”,
“lat”:“17.4166067”,
“液化天然气”:“78.4853992”,
“说明”:“15”
}
];
var映射;
变量映射选项={
中心:新建google.maps.LatLng(标记[0].lat,标记[0].lng),
缩放:15,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
var path=new google.maps.MVCArray();
var service=new google.maps.DirectionsService();
var infoWindow=new google.maps.infoWindow();
var map=new google.maps.map(document.getElementById(“map”)、mapOptions);
var poly=new google.maps.Polyline({
地图:地图,
strokeColor:“#000000”
});
var lat_lng=新阵列();
对于(var i=0;iGoogle reccomends:

通过优化应用程序以更高效地使用web服务来降低使用率

尽可能增加使用限制,为您的谷歌地图API工作许可证购买额外津贴

此外,还有一些变通办法,似乎适合您的需要

if status == "OVER_QUERY_LIMIT": 
    time.sleep(2)
这是用Phyton编写的,但您可以使用它,因为它易于阅读:

url = "MAPS_API_WEBSERVICE_URL"
attempts = 0
success = False

while success != True and attempts < 3:
  raw_result = urllib.urlopen(url).read()
  attempts += 1
  # The GetStatus function parses the answer and returns the status code
  # This function is out of the scope of this example (you can use a SDK).
  status = GetStatus(raw_result)
  if status == "OVER_QUERY_LIMIT":
    time.sleep(2)
    # retry
    continue
  success = True

if attempts == 3:
  # send an alert as this means that the daily limit has been reached
  print "Daily limit has been reached"

检查一下

我已经提到了@Andreas,但它没有提到如何去做,这对我来说是很难假装的。非常感谢你的时间和回复@Jordi..我试图在JScript中实现你的概念..我会告诉你什么时候处理完ittell我如果你有疑问…我可以帮你处理
javascript
code;)如果您在jscript中编辑您的答案,而jscript可以处理此问题,那么这将非常有帮助:)在我的答案更新中,你有工作的小提琴和相关的代码行。。。希望有帮助…您好@Jordi…非常感谢您的耐心,但很抱歉,is路径仍然不完整。正如您所看到的,源(绿点)和目标(红点)未满足要求。路径线在到达目标之前停止
if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT)
{      
    setTimeout(3000);
}