Created
November 15, 2010 13:47
-
-
Save robotlolita/700371 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// your function | |
function calcDistance (start, end) { | |
var distance=9999999; | |
var request = { | |
origin:start, | |
destination:end, | |
travelMode: google.maps.DirectionsTravelMode.DRIVING | |
}; | |
directionsService.route(request, function(result, status) { | |
if (status == google.maps.DirectionsStatus.OK) { | |
distance = result.routes[0].legs[0].distance.value; | |
//document.getElementById('distance').innerHTML = "Distance: " + | |
// distance + " meters"; | |
// return the distance: | |
} | |
}); | |
return distance; | |
} | |
// ----------------------------------------- | |
// how JavaScript executes it | |
function calcDistance(start, end) -> | |
let distance be 9999999 | |
start a request for the content in the `request` object. | |
return the distance // at this point, the request you initiated in the previous line hasn't returned yet | |
someDistance = calcDistance(0,1) // 9999999, because return is always executed before the request has a chance of begin run | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment