Route Terrain Profile
In this guide you will learn how to obtain and display terrain statistics for a route, given the coordinates of the departure and destination points. The terrain profile statistics include the minimum and the maximum elevation above sea level in meters, as well as the total vertical meters climbed, and the total vertical meters descended during the route.
Open the MainActivity.kt
file to see how the route terrain profile statistics are obtained and displayed.
The MainActivity
overrides the onCreate
function which checks that internet access is available using Util.isInternetConnected()
and calls the calculateRoute()
function after the map is instantiated, as indicated by the isReady
flag.
The calculateRoute()
function computes a route between two or more landmarks, given as a list of waypoints, where the first one is the departure point, and the last one is the destination point.
The landmarks contain a name, latitude and longitude, in degrees.
routingService.preferences.buildTerrainProfile
has to be set to true
before routingService.calculateRoute(waypoints)
in order to also get the terrain profile statistics.
The above function, displayTerrainInfo()
displays some basic statistics about the computed route in this example in text format, to show how to access the terrain profile data.
The RouteTerrainProfile
class contains a lot of information, but this example presents only the minimum and maximum elevation above sea level in meters, elevation at a certain point along the route, the total vertical meters ascending and descending, and the number of climbing sections in the selected route.
To display a chart representing the elevation of the route, the method getElevationSamples(samplesCount)
can be used, specifying the number of samples, and thus resolution, of the resulting terrain data.
There are also additional methods about route terrain profile in the documentation.