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

Distance matrix is not returning distance for large data

我正在尝试 return 距离 google 距离矩阵服务。它 returns 60-100 个数据的距离。但是对于超过100的大数据,就不行了。我所做的是,

   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);

这是内循环。

回调函数是:

  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 = [];
    }
    } 
    }

我认为代码没有错误,因为它适用于小数据。那么我怎样才能确保函数为大数据返回数据。有什么办法吗。我搜了一下,here and 。它描述的问题与我的不同。谢谢你。非常感谢任何形式的帮助。

可以返回结果的起点乘以终点的数量有限制:

来自 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.