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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料