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.