title: google distance matrix API 3
body: <p>I have code to calculate distance place to another place using google distance matrix API, but for free its limited just 100 elements per query. So I make code for solve the problem using looping code such as for elements , My code is PHP, javascript , and I parse latitude and longitude data from MySql. Anyone know some error of my code below ? because It don't appear anything if I click calculate button. Actualy I have modifie the code from this URL <a href="https://google-developers.appspot.com/maps/documentation/javascript/examples/distance-matrix" rel="nofollow">https://google-developers.appspot.com/maps/documentation/javascript/examples/distance-matrix</a> , And this is my Code :</p>
  
  <pre><code>function hitung (){
    service = new google.maps.DistanceMatrixService();
      for (m = 0 ; m &lt; l-80 ; m++ ){
          asal = originarray[m];
          for (n = 0 ; n &lt; l-80 ; n++ ){
              tujuan = destarray [n];
              calculateDistances();
          }
      }
    }
    function calculateDistances() {
  
   //var s = 0;
  
    //for (m = 0 ; m &lt; l-80 ; m++ ){
      //  asal = originarray[m];
      //for (n = 0 ; n &lt; l-80 ; n++ ){
          //servicearray[s] = new google.maps.DistanceMatrixService();
          //tujuan = destarray [n];       
          service.getDistanceMatrix(
        {
         //origins: [origin1, origin2],
        // destinations: [destinationA, destinationB],
         origins: asal,
       destinations: tujuan,
          //origins: originarray,
          //destinations: destarray,
          travelMode: google.maps.TravelMode.DRIVING,
          unitSystem: google.maps.UnitSystem.METRIC,
          avoidHighways: false,
          avoidTolls: false
        }, callback);
       // s++;
  
      //}
  
  // }        
    }
  
    function callback(response, status) {
      if (status != google.maps.DistanceMatrixStatus.OK) {
        alert('Error was: ' + status);
      } else {
        var origins = response.originAddresses;
        var destinations = response.destinationAddresses;
        var outputDiv = document.getElementById('outputDiv');
        //outputDiv.innerHTML = '';
       // deleteOverlays();
  
        for (var i = 0; i &lt; origins.length; i++) {
          var results = response.rows[i].elements;
         // addMarker(origins[i], false);
          for (var j = 0; j &lt; results.length; j++) {
          //  addMarker(destinations[j], true);
            outputDiv.innerHTML += origins[i] + ' to ' + destinations[j]
                + ': ' + results[j].distance.text + ' in '
                + results[j].duration.text + '&lt;br&gt;';
          }
        }
      }
    }
  
    function addMarker(location, isDestination) {
      var icon;
      if (isDestination) {
        icon = destinationIcon;
      } else {
        icon = originIcon;
      }
      geocoder.geocode({'address': location}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          bounds.extend(results[0].geometry.location);
          map.fitBounds(bounds);
          var marker = new google.maps.Marker({
            map: peta,
            position: results[0].geometry.location,
            icon: icon
          });
          markersArray.push(marker);
        } else {
          alert('Geocode was not successful for the following reason: '
            + status);
        }
      });
    }
  
    function deleteOverlays() {
      if (markersArray) {
        for (i in markersArray) {
          markersArray[i].setMap(null);
        }
        markersArray.length = 0;
      }
    }
  
  &lt;/script&gt;
  </code></pre>
  
  <p></p>