[Routing API] Get elevation and decode polyline
Question
How to get the elevation or altitude of the calculated route as follows?
Answer
HERE Routing API provide elevation in return, so you just need to specify "elevation" to be returned:<br />https://router.hereapi.com/v8/routes?origin=52.607668,13.870194&destination=52.631988,13.852766&return=polyline,elevation&transportMode=car&apikey=YOUR_API_KEY<br />
The elevation or altitude information of the route is included in the returned polyline:
B2Fqr9qkDwnyuaosCCAA4I7GAsErEAoL_OUkhB7zBA0KnQU0UnfUoLjXUoGzPU8GvWU4DvRA4I74BoBsE3SAwHjXUgKnVAwlBrlCoBwW7pBA0KvWA4D3IAkN7fUwvBryDT4S_sBTokBn2CA0P7kBAgKzUTgK7LAsOzKUoL_EAoVzFA4pCrOUkzHjwBgF88EzewCk2Sj2DgF4e9FA
Sample
The following code installes the flexpolyline commandline tool and use it to decode the polyline returned from the Routing API:<br />% cargo --versioncargo 1.75.0 (1d8b05cdd 2023-11-20)% cargo install flexpolyline Updating crates.io index Downloaded flexpolyline v1.0.0 Downloaded 1 crate (9.5 KB) in 4.77s Installing flexpolyline v1.0.0 Updating crates.io index Compiling flexpolyline v1.0.0 Finished release [optimized] target(s) in 12.80s Installing /Users/jiangling/.cargo/bin/flexpolyline Installed package `flexpolyline v1.0.0` (executable `flexpolyline`)% echo B2Fqr9qkDwnyuaosCCAA4I7GAsErEAoL_OUkhB7zBA0KnQU0UnfUoLjXUoGzPU8GvWU4DvRA4I74BoBsE3SAwHjXUgKnVAwlBrlCoBwW7pBA0KvWA4D3IAkN7fUwvBryDT4S_sBTokBn2CA0P7kBAgKzUTgK7LAsOzKUoL_EAoVzFA4pCrOUkzHjwBgF88EzewCk2Sj2DgF4e9FA | flexpolyline decode --original-precision {(6, 1, 3); [(52.607669, 13.870200, 122.0), (52.607670, 13.870200, 122.0), (52.607810, 13.870090, 122.0), (52.607880, 13.870020, 122.0), (52.608060, 13.869780, 123.0), (52.608590, 13.868950, 123.0), (52.608760, 13.868690, 124.0), (52.609090, 13.868190, 125.0), (52.609270, 13.867820, 126.0), (52.609370, 13.867570, 127.0), (52.609480, 13.867210, 128.0), (52.609540, 13.866930, 128.0), (52.609680, 13.866020, 130.0), (52.609750, 13.865720, 130.0), (52.609870, 13.865350, 131.0), (52.610030, 13.865010, 131.0), (52.610630, 13.863900, 133.0), (52.610990, 13.863230, 133.0), (52.611160, 13.862870, 133.0), (52.611220, 13.862730, 133.0), (52.611430, 13.862220, 134.0), (52.612190, 13.860390, 133.0), (52.612490, 13.859670, 132.0), (52.613070, 13.858290, 132.0), (52.613320, 13.857700, 132.0), (52.613480, 13.857370, 131.0), (52.613640, 13.857180, 131.0), (52.613870, 13.857010, 132.0), (52.614050, 13.856930, 132.0), (52.614390, 13.856840, 132.0), (52.615570, 13.856610, 133.0), (52.619460, 13.855840, 141.0), (52.621970, 13.855350, 145.0), (52.631540, 13.853460, 153.0), (52.632032, 13.853365, 153.0), ]}<br />
The elevation or altitude information is included in response for each location, after the geo coordinates values.
SDK
For HERE SDK, the elevataion or altitude information is included in the GeoPolyline of the calculated route.
You can confirm its availability with our Routing SDK example app with the route.getGeometry() method:
SDK also support MapFeatures.TERRAIN with MapFeatureModes.TERRAIN_3D shows topographical shading for hills on a 3D terrain map
If you want to test this feature, choosing a location with sufficient latitude to present the terrain view in 3D is important.
For example, you can use (42.99788, -0.60113) as above or (45.9122,10.8855) as the guide Visualize terrain data in 3D with HERE DEM used.