Skip to content

Instantly share code, notes, and snippets.

@ShenXuGongZi
Created August 13, 2012 08:54
Show Gist options
  • Save ShenXuGongZi/3338416 to your computer and use it in GitHub Desktop.
Save ShenXuGongZi/3338416 to your computer and use it in GitHub Desktop.
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