Class ElevationSampler Stay organized with collections Save and categorize content based on your preferences.
Page Summary
ElevationSampler allows you to sample elevations at specific locations.
You can use ElevationSampler to find the highest point along a route and plot it on a map.
Methods are available to sample elevation for single points, multiple points, or along a path defined by points or an encoded polyline.
The sample methods return a JSON object containing elevation data.
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 routefrom 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.constdirections=Maps.newDirectionFinder().setOrigin('Denver, CO').setDestination('Grand Junction, CO').setMode(Maps.DirectionFinder.Mode.DRIVING).getDirections();constroute=directions.routes[0];// Get elevation samples along the route.constnumberOfSamples=30;constresponse=Maps.newElevationSampler().samplePath(route.overview_polyline.points,numberOfSamples,);// Determine highest point.lethighestLocation=null;lethighestElevation=Number.MIN_VALUE;for(constsampleofresponse.results){if(sample.elevation >highestElevation){highestElevation=sample.elevation;highestLocation=sample.location;}}// Add the path and marker to a map.constmap=Maps.newStaticMap().addPath(route.overview_polyline.points).addMarker(highestLocation.lat,highestLocation.lng);// Save the map to your driveDriveApp.createFile(Utilities.newBlob(map.getMapImage(),'image/png','map.png'),);
See also
Methods
| Method | Return type | Brief description |
|---|---|---|
sample | Object | Returns elevation data for a single point (lat/lng). |
sample | Object | Returns elevation data for a series of points (lat/lng). |
sample | Object | Returns elevation data for the points in an encoded polyline. |
sample | Object | Returns elevation data for a number of samples along a line, defined using a series of points. |
sample | Object | Returns elevation data for a number of samples along a line, defined using an encoded polyline. |
Detailed documentation
sampleLocation(latitude, longitude)
Returns elevation data for a single point (lat/lng).
// Gets the elevation of Times Square using a point.constdata=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 describedhere
sampleLocations(points)
Returns elevation data for a series of points (lat/lng).
// Gets the elevation of Times Square and Central Park using points.constdata=Maps.newElevationSampler().sampleLocations([// Times Square40.759011,-73.984472,// Central Park40.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 describedhere
sampleLocations(encodedPolyline)
Returns elevation data for the points in an encoded polyline.
// Gets the elevation of Times Square and Central Park using a polyline.constdata=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 | String | an encoded polyline of points to sample |
Return
Object — a JSON Object containing the elevation data, as describedhere
samplePath(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.constdata=Maps.newElevationSampler().samplePath([// Times Square40.759011,-73.984472,// Central Park40.777052,-73.975464,],5,);for(leti=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 | Integer | the number of points to sample along the path of points |
Return
Object — a JSON Object containing the elevation data, as describedhere
samplePath(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.constdata=Maps.newElevationSampler().samplePath('yvwwF|aqbMwoBiw@',5);for(leti=0;i <data.results.length;i++){Logger.log(data.results[i].elevation);}
Parameters
| Name | Type | Description |
|---|---|---|
encoded | String | an encoded polyline of points defining a path to sample over |
num | Integer | the number of points to sample along the path of points |
Return
Object — a JSON Object containing the elevation data, as describedhere
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.