Route geometry in HERE Routing API v8
HERE Routing API v8 can present the geometry of a route as a polyline compressed with Flexible Polyline encoding - a lossy compressed representation of a list of coordinate pairs or coordinate triples.
To get a two-dimensional shape of a route, add return=polyline to your route calculation request.
The API returns a polyline field for each section of the route. The field contains an encoded polyline which can be decoded using the following tools:
- Implementations in various languages available in the Flexible Polyline repository.
- HERE Maps API for JavaScript: see this example to learn more.
- Command-line interfaces like flexpolyline.
Example
The following request returns a polyline in the API response:
curl -gX GET 'https://router.hereapi.com/v8/routes?'\
'transportMode=car&'\
'origin=52.5308,13.3847&'\
'destination=52.5323,13.3789&'\
'return=polyline&'\
'apiKey=YOUR_API_KEY'{
"routes": [
{
"id": "81e526c0-5693-4bc0-bdbb-239ecc2857e7",
"sections": [
{
...,
"polyline": "BGwynmkDu39wZvBtF3InfvHrdvHvboGzF0FnGoGvHsOvR8L3NkSvWoGvHsEzFgFvHkD3IwHrJwHrJgKjN4D_E0ezoBjInV3N_iBzJ_Z",
"transport": {
"mode": "car"
},
"type": "vehicle"
}
]
}
]
}Decoding the polyline using flexpolyline produces the following output:
echo BGwynmkDu39wZvBtF3InfvHrdvHvboGzF0FnGoGvHsOvR8L3NkSvWoGvHsEzFgFvHkD3IwHrJwHrJgKjN4D_E0ezoBjInV3N_iBzJ_Z | flexpolyline decode --original-precision
{(6);
[(52.530984, 13.384567),
(52.530960, 13.384480),
(52.530820, 13.383980),
(52.530700, 13.383510),
(52.530580, 13.383070),
(52.530680, 13.382980),
(52.530770, 13.382880),
(52.530870, 13.382760),
(52.531100, 13.382480),
(52.531290, 13.382260),
(52.531580, 13.381900),
(52.531680, 13.381780),
(52.531750, 13.381690),
(52.531830, 13.381570),
(52.531880, 13.381430),
(52.532000, 13.381280),
(52.532120, 13.381130),
(52.532280, 13.380920),
(52.532340, 13.380840),
(52.532830, 13.380190),
(52.532700, 13.379850),
(52.532480, 13.379290),
(52.532326, 13.378874), ]}
Elevation profile
To get the elevation profile encoded in the polyline (get a three-dimensional polyline), add return=polyline,elevation to your route calculation request.
The following code snippets are a sample request, response, and the decoding of the polyline:
curl -gX GET 'https://router.hereapi.com/v8/routes?'\
'transportMode=car&'\
'origin=52.5308,13.3847&'\
'destination=52.5323,13.3789&'\
'return=polyline,elevation&'\
'apiKey=YOUR_API_KEY'{
"routes": [
{
"id": "81e526c0-5693-4bc0-bdbb-239ecc2857e7",
"sections": [
{
...,
"polyline": "B2FwynmkDu39wZouBvBtFA3InfAvHrdAvHvbAoGzFA0FnGAoGvHUsOvRA8L3NAkSvWAoGvHAsEzFAgFvHAkD3IAwHrJAwHrJAgKjNA4D_EA0ezoBAjInVA3N_iBAzJ_ZA",
"transport": {
"mode": "car"
},
"type": "vehicle"
}
]
}
]
}echo BGwynmkDu39wZvBtF3InfvHrdvHvboGzF0FnGoGvHsOvR8L3NkSvWoGvHsEzFgFvHkD3IwHrJwHrJgKjN4D_E0ezoBjInV3N_iBzJ_Z | flexpolyline decode --original-precision
{(6, 1, 3);
[(52.530984, 13.384567, 74.0),
(52.530960, 13.384480, 74.0),
(52.530820, 13.383980, 74.0),
(52.530700, 13.383510, 74.0),
(52.530580, 13.383070, 74.0),
(52.530680, 13.382980, 74.0),
(52.530770, 13.382880, 74.0),
(52.530870, 13.382760, 75.0),
(52.531100, 13.382480, 75.0),
(52.531290, 13.382260, 75.0),
(52.531580, 13.381900, 75.0),
(52.531680, 13.381780, 75.0),
(52.531750, 13.381690, 75.0),
(52.531830, 13.381570, 75.0),
(52.531880, 13.381430, 75.0),
(52.532000, 13.381280, 75.0),
(52.532120, 13.381130, 75.0),
(52.532280, 13.380920, 75.0),
(52.532340, 13.380840, 75.0),
(52.532830, 13.380190, 75.0),
(52.532700, 13.379850, 75.0),
(52.532480, 13.379290, 75.0),
(52.532326, 13.378874, 75.0), ]}Updated 10 days ago