How to calculate a matrix in Profile mode
The following tutorial provides an example of a 7 x 7 matrix request with these origins and destinations:
- Berlin at (52.54, 13.40)
- Kyiv at (50.43, 30.52)
- London at (51.50, -0.08)
- Madrid at (40.40, -3.68)
- Moscow at (55.75, 37.60)
- Paris at (48.87, 2.33)
- Rome at (41.90, 12.48)
To calculate a car distance matrix, you can use the request below. Since the request does not specify the destinations array, the origins are taken as destinations and the resulting matrix is a 7 x 7 matrix.
The region definition is the special variant world. In the request, we use the profile carFast which uses transport mode car and optimizes the route calculations for travel time.
By default, the service calculates a travel times matrix, but since we want to get distances in the response instead of times, the request specifies the matrixAttributes property with the value distances.
{
"origins": [
{ "lat": 52.54, "lng": 13.40 },
{ "lat": 50.43, "lng": 30.52 },
{ "lat": 51.50, "lng": -0.08 },
{ "lat": 40.40, "lng": -3.68 },
{ "lat": 55.75, "lng": 37.60 },
{ "lat": 48.87, "lng": 2.33 },
{ "lat": 41.90, "lng": 12.48 }
],
"profile": "carFast",
"regionDefinition": {
"type": "world"
},
"matrixAttributes": ["distances"]
}Visualized, it looks as follows:
The full procedure of submitting a matrix request is described in the Get started with HERE Matrix Routing API v8 section. The response looks as follows:
{
"matrixId": "d68e214a-52f7-4b67-858a-d67935cce61b",
"matrix": {
"numOrigins": 7,
"numDestinations": 7,
"distances": [
0, 1360978, 1093439, 2319223, 1836226, 1052278, 1508389,
1346659, 0, 2395659, 3621443, 853752, 2354498, 2445588,
1101711, 2404221, 0, 1719756, 2879469, 456781, 1838456,
2317959, 3620469, 1711156, 0, 4095717, 1271140, 1961961,
1823692, 851480, 2872692, 4098476, 0, 2831531, 3054079,
1051198, 2353708, 452120, 1272365, 2828956, 0, 1426684,
1507836, 2441104, 1832407, 1963512, 3049976, 1424346, 0
]
},
"regionDefinition": {
"type": "world"
}
}The response corresponds to this matrix with entries in meters:
| orig\dest | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| 1 | 0 | 1360978 | 1093439 | 2319223 | 1836226 | 1052278 | 1508389 |
| 2 | 1346659 | 0 | 2395659 | 3621443 | 853752 | 2354498 | 2445588 |
| 3 | 1101711 | 2404221 | 0 | 1719756 | 2879469 | 456781 | 1838456 |
| 4 | 2317959 | 3620469 | 1711156 | 0 | 4095717 | 1271140 | 1961961 |
| 5 | 1823692 | 851480 | 2872692 | 4098476 | 0 | 2831531 | 3054079 |
| 6 | 1051198 | 2353708 | 452120 | 1272365 | 2828956 | 0 | 1426684 |
| 7 | 1507836 | 2441104 | 1832407 | 1963512 | 3049976 | 1424346 | 0 |
Updated 8 days ago