Created
August 13, 2012 08:54
-
-
Save ShenXuGongZi/3338416 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
function getElevation(event) { | |
var elevator; | |
elevator = new google.maps.ElevationService(); | |
var locations = []; | |
// Retrieve the clicked location and push it on the array | |
var clickedLocation = event.latLng; | |
locations.push(clickedLocation); | |
// Create a LocationElevationRequest object using the array's one value | |
var positionalRequest = { | |
'locations': locations | |
} | |
// Initiate the location request | |
elevator.getElevationForLocations(positionalRequest, function(results, status) { | |
if (status == google.maps.ElevationStatus.OK) { | |
// Retrieve the first result | |
if (results[0]) { | |
// Open an info window indicating the elevation at the clicked position | |
var altitude = '' + results[0].elevation + '' | |
alert(altitude); | |
} else { | |
alert('No results found'); | |
} | |
} else { | |
alert('Elevation service failed due to: ' + status); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment