gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 03:00:38 24 4
gpt4 key购买 nike

我正在尝试通过 google Distance Matrix Service 返回距离。它返回 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);

这是内部循环。

调用 bac 函数是:

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

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

最佳答案

可返回结果的出发地和目的地的数量有限制:

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

关于javascript - 距离矩阵不返回大数据的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47405912/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com