1

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.

Tekraj Shrestha
  • 1,228
  • 3
  • 20
  • 48

1 Answers1

3

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.

Community
  • 1
  • 1
geocodezip
  • 158,664
  • 13
  • 220
  • 245