title: Javascript Pass Parameter to Callback or Set Variable Value in DistanceMatrixStatus
body: <p>I have been playing a little bit with Google's DistanceMatrixService. The code below works, but, how can I pass another parameter to the callback function or grab one of the values out of the callback?</p>
  
  <p>For example: I have two divs that I want to show different results in (Results1 and Results2), so I am thinking I need to either<br>
  pass another value to the GoogleMapDistance function like <i>GoogleMapDistance(YourLatLong,DestLatLong,TheDiv)</i><br>
  or<br>
  be able to grab the ResultStr externally outside of the callback <i>document.getElementById("Results1").innerHTML = ResultStr;</i><br>
  or<br>
  set the innerHTM to the returned value of the function document.getElementById("Results1").innerHTML = GoogleMapDistance(YourLatLong,DestLatLong);  </p>
  
  <p>I'm stuck. How can I do accomplish this? The way it looks right now is that I am only going to be able to run all this code once and have it only write to one div.</p>
  
  <pre><code>&lt;div id="Results1"&gt;&lt;/div&gt;
  &lt;div id="Results2"&gt;&lt;/div&gt;
  
  &lt;script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false"&gt;&lt;/script&gt;
  &lt;script&gt;
  
  function GoogleMapDistance(YourLatLong,DestLatLong)
  {
      var service = new google.maps.DistanceMatrixService();
      service.getDistanceMatrix(
      {
      origins: [YourLatLong],
      destinations: [DestLatLong],
      travelMode: google.maps.TravelMode.DRIVING,
      unitSystem: google.maps.UnitSystem.IMPERIAL,
      avoidHighways: false,
      avoidTolls: false
      }, callback);
  }
  
  function callback(response, status)
  {
      if (status == google.maps.DistanceMatrixStatus.OK)
      {
      var origins = response.originAddresses;
      var destinations = response.destinationAddresses;
        for (var i = 0; i &lt; origins.length; i++)
        {
            var results = response.rows[i].elements;
            for (var j = 0; j &lt; results.length; j++)
            {
                var element = results[j];
                var from = origins[i];
                var to = destinations[j];
                var distance = element.distance.text;
                var duration = element.duration.text;
                var ResultStr = distance + "&amp;nbsp; (&lt;i&gt;" + duration + "&lt;/i&gt;)";
            }
        }
      document.getElementById("Results1").innerHTML = ResultStr;
      }
  }
  
  var YourLatLong = "45.4049,-122.797997";
  var DestLatLong1 = "47.468893,-122.227978";
  var DestLatLong2 = "61.221274,-149.831545";
  
  GoogleMapDistance(YourLatLong,DestLatLong1);
  
  &lt;/script&gt;
  </code></pre>