title: Google Distance Matrix need to return the value
body: <p>I have using google distance matrix api to getting the shortest distance of two geo points from the following way:</p>
  
  <pre><code>&lt;script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;signed_in=true"&gt;&lt;/script&gt;
  &lt;script&gt;
  
      var origin1 = new google.maps.LatLng(9.6667, 80.0000);
      var destinationA = new google.maps.LatLng(9.6689, 80.0059);
  
  
  
      function calculateDistances() {
  
  
          var service = new google.maps.DistanceMatrixService();
          service.getDistanceMatrix(
              {
                  origins: [origin1],
                  destinations: [destinationA],
                  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) {
              alert('Error was: ' + status);
          } else {
              var origins = response.originAddresses;
  
  
              for (var i = 0; i &lt; origins.length; i++) {
                  var results = response.rows[i].elements;
                  for (var j = 0; j &lt; results.length; j++) {
                      alert(results[j].distance.text);
                  }
              }
          }
      }
  
  
  &lt;/script&gt;
  </code></pre>
  
  <p>On this code I have get the shortest distance successfully. But I need to return the value when calling the method <strong>calculateDistances()</strong> instead of alert the value. How can i do in callback methods!.</p>