GuidesAPI Reference
Guides

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:

  1. Berlin at (52.54, 13.40)
  2. Kyiv at (50.43, 30.52)
  3. London at (51.50, -0.08)
  4. Madrid at (40.40, -3.68)
  5. Moscow at (55.75, 37.60)
  6. Paris at (48.87, 2.33)
  7. 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: Matrix request in Europe 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\dest1234567
10136097810934392319223183622610522781508389
2134665902395659362144385375223544982445588
3110171124042210171975628794694567811838456
42317959362046917111560409571712711401961961
5182369285148028726924098476028315313054079
6105119823537084521201272365282895601426684
71507836244110418324071963512304997614243460