duanliaozhi2915 2017-11-21 05:36
浏览 30
已采纳

距离矩阵不是大数据的返回距离

I am trying to return the distance eith google Distance Matrix Service. It returns the distance for 60-100 data. But for large data more than 100, it does not works. What I have done is,

   var service = new google.maps.DistanceMatrixService(); 
    service.getDistanceMatrix({
    origins: [origin],
    destinations: [dest],
    travelMode: google.maps.TravelMode.DRIVING,
    unitSystem: google.maps.UnitSystem.METRIC,
    avoidHighways: false,
    avoidTolls: false
    }, callback);

This is inside loop.

the call bac function is :

  function callback(response, status) {
    if (status == google.maps.DistanceMatrixStatus.OK) {
    var origins = response.originAddresses;
    var destinations = response.destinationAddresses;
    for (var i = 0; i < origins.length; i++) {
    var results = response.rows[i].elements;
    for (var j = 0; j < results.length; j++) {
    var element = results[j];
    var distance =(parseFloat(element.distance.value)/1000).toFixed(1);
    var un = '';
    if($('input[name=distance-units]:checked').val()=='kms'){
    un = themiles;
    } else {
    un = thekm;
    }
    var duration = element.duration.text;
    var from = origins[i];
    var to = destinations[j];
    arr.push(distance);
    }
    }

    distancecode++;
    if(distancecode==(totalrec+1)){
    distancecode=0;
    arr.sort(function(a,b){return a-b});
    for(k=0;k<=arr.length;k++){

    $('#d_'+(k+1)+' .value').html(arr[k]);

    $('#d_'+(k+1)+' .units').html(un);
    }
    arr = [];
    }
    } 
    }

I don't think there is error in code as it is working for small data. So how can I make sure the function retuns data for large data. Is there any way. I searched for it, here and here. It described problem different than mine. Thank you. Any kind of help are highly appreciated.

  • 写回答

1条回答 默认 最新

  • dougua3706 2017-11-21 07:23
    关注

    There is a limit to the number of origins times destinations that results can be returned for:

    from the documentation

    Quotas#

    The following usage limits are in place for the Distance Matrix service: Note: each query sent to the Distance Matrix service is limited by the number of allowed elements, where the number of origins times the number of destinations defines the number of elements.

    Maximum of 25 origins or 25 destinations per request.
    Maximum 100 elements per request.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算