Class ElevationSampler

Elevation Sampler

Allows for the sampling of elevations at particular locations.The example below shows how you can use this class to determine the highest point along the route from Denver to Grand Junction in Colorado, plot it on a map, and save the map to Google Drive.

 // Get directions from Denver to Grand Junction. 
 const 
  
 directions 
  
 = 
  
 Maps 
 . 
 newDirectionFinder 
 () 
  
 . 
 setOrigin 
 ( 
 'Denver, CO' 
 ) 
  
 . 
 setDestination 
 ( 
 'Grand Junction, CO' 
 ) 
  
 . 
 setMode 
 ( 
 Maps 
 . 
 DirectionFinder 
 . 
 Mode 
 . 
 DRIVING 
 ) 
  
 . 
 getDirections 
 (); 
 const 
  
 route 
  
 = 
  
 directions 
 . 
 routes 
 [ 
 0 
 ]; 
 // Get elevation samples along the route. 
 const 
  
 numberOfSamples 
  
 = 
  
 30 
 ; 
 const 
  
 response 
  
 = 
  
 Maps 
 . 
 newElevationSampler 
 (). 
 samplePath 
 ( 
  
 route 
 . 
 overview_polyline 
 . 
 points 
 , 
  
 numberOfSamples 
 , 
 ); 
 // Determine highest point. 
 let 
  
 highestLocation 
  
 = 
  
 null 
 ; 
 let 
  
 highestElevation 
  
 = 
  
 Number 
 . 
 MIN_VALUE 
 ; 
 for 
  
 ( 
 const 
  
 sample 
  
 of 
  
 response 
 . 
 results 
 ) 
  
 { 
  
 if 
  
 ( 
 sample 
 . 
 elevation 
 > 
 highestElevation 
 ) 
  
 { 
  
 highestElevation 
  
 = 
  
 sample 
 . 
 elevation 
 ; 
  
 highestLocation 
  
 = 
  
 sample 
 . 
 location 
 ; 
  
 } 
 } 
 // Add the path and marker to a map. 
 const 
  
 map 
  
 = 
  
 Maps 
 . 
 newStaticMap 
 () 
  
 . 
 addPath 
 ( 
 route 
 . 
 overview_polyline 
 . 
 points 
 ) 
  
 . 
 addMarker 
 ( 
 highestLocation 
 . 
 lat 
 , 
  
 highestLocation 
 . 
 lng 
 ); 
 // Save the map to your drive 
 DriveApp 
 . 
 createFile 
 ( 
  
 Utilities 
 . 
 newBlob 
 ( 
 map 
 . 
 getMapImage 
 (), 
  
 'image/png' 
 , 
  
 'map.png' 
 ), 
 ); 

See also

Methods

Method Return type Brief description
Object Returns elevation data for a single point (lat/lng).
Object Returns elevation data for a series of points (lat/lng).
Object Returns elevation data for the points in an encoded polyline.
Object Returns elevation data for a number of samples along a line, defined using a series of points.
Object Returns elevation data for a number of samples along a line, defined using an encoded polyline.

Detailed documentation

sample Location(latitude, longitude)

Returns elevation data for a single point (lat/lng).

 // Gets the elevation of Times Square using a point. 
 const 
  
 data 
  
 = 
  
 Maps 
 . 
 newElevationSampler 
 (). 
 sampleLocation 
 ( 
 40.759011 
 , 
  
 - 
 73.984472 
 ); 
 Logger 
 . 
 log 
 ( 
 data 
 . 
 results 
 [ 
 0 
 ]. 
 elevation 
 ); 

Parameters

Name Type Description
latitude
Number the latitude of the point to sample
longitude
Number the longitude of the point to sample

Return

Object — a JSON Object containing the elevation data, as described here


sample Locations(points)

Returns elevation data for a series of points (lat/lng).

 // Gets the elevation of Times Square and Central Park using points. 
 const 
  
 data 
  
 = 
  
 Maps 
 . 
 newElevationSampler 
 (). 
 sampleLocations 
 ([ 
  
 // Times Square 
  
 40.759011 
 , 
  
 - 
 73.984472 
 , 
  
 // Central Park 
  
 40.777052 
 , 
  
 - 
 73.975464 
 , 
 ]); 
 Logger 
 . 
 log 
 ( 
 `Times Square: 
 ${ 
 data 
 . 
 results 
 [ 
 0 
 ]. 
 elevation 
 } 
 ` 
 ); 
 Logger 
 . 
 log 
 ( 
 `Central Park: 
 ${ 
 data 
 . 
 results 
 [ 
 1 
 ]. 
 elevation 
 } 
 ` 
 ); 

Parameters

Name Type Description
points
Number[] an array of latitude/longitude pairs

Return

Object — a JSON Object containing the elevation data, as described here


sample Locations(encodedPolyline)

Returns elevation data for the points in an encoded polyline.

 // Gets the elevation of Times Square and Central Park using a polyline. 
 const 
  
 data 
  
 = 
  
 Maps 
 . 
 newElevationSampler 
 (). 
 sampleLocations 
 ( 
 'yvwwF|aqbMwoBiw@' 
 ); 
 Logger 
 . 
 log 
 ( 
 `Times Square: 
 ${ 
 data 
 . 
 results 
 [ 
 0 
 ]. 
 elevation 
 } 
 ` 
 ); 
 Logger 
 . 
 log 
 ( 
 `Central Park: 
 ${ 
 data 
 . 
 results 
 [ 
 1 
 ]. 
 elevation 
 } 
 ` 
 ); 

Parameters

Name Type Description
encoded Polyline
String an encoded polyline of points to sample

Return

Object — a JSON Object containing the elevation data, as described here


sample Path(points, numSamples)

Returns elevation data for a number of samples along a line, defined using a series of points.

 // Gets the elevation of five points between Times Square and Central Park. 
 const 
  
 data 
  
 = 
  
 Maps 
 . 
 newElevationSampler 
 (). 
 samplePath 
 ( 
  
 [ 
  
 // Times Square 
  
 40.759011 
 , 
  
 - 
 73.984472 
 , 
  
 // Central Park 
  
 40.777052 
 , 
  
 - 
 73.975464 
 , 
  
 ], 
  
 5 
 , 
 ); 
 for 
  
 ( 
 let 
  
 i 
  
 = 
  
 0 
 ; 
  
 i 
 < 
 data 
 . 
 results 
 . 
 length 
 ; 
  
 i 
 ++ 
 ) 
  
 { 
  
 Logger 
 . 
 log 
 ( 
 data 
 . 
 results 
 [ 
 i 
 ]. 
 elevation 
 ); 
 } 

Parameters

Name Type Description
points
Number[] an array of latitude/longitude pairs defining a path to sample over
num Samples
Integer the number of points to sample along the path of points

Return

Object — a JSON Object containing the elevation data, as described here


sample Path(encodedPolyline, numSamples)

Returns elevation data for a number of samples along a line, defined using an encoded polyline.

 // Gets the elevation of five points between Times Square and Central Park. 
 const 
  
 data 
  
 = 
  
 Maps 
 . 
 newElevationSampler 
 (). 
 samplePath 
 ( 
 'yvwwF|aqbMwoBiw@' 
 , 
  
 5 
 ); 
 for 
  
 ( 
 let 
  
 i 
  
 = 
  
 0 
 ; 
  
 i 
 < 
 data 
 . 
 results 
 . 
 length 
 ; 
  
 i 
 ++ 
 ) 
  
 { 
  
 Logger 
 . 
 log 
 ( 
 data 
 . 
 results 
 [ 
 i 
 ]. 
 elevation 
 ); 
 } 

Parameters

Name Type Description
encoded Polyline
String an encoded polyline of points defining a path to sample over
num Samples
Integer the number of points to sample along the path of points

Return

Object — a JSON Object containing the elevation data, as described here

Create a Mobile Website
View Site in Mobile | Classic
Share by: