Calculate Matrix with Routes of Arbitrary Length

Given a list of origins and a list of destinations, the service computes the shortest travel times or distances between every pair of origin and destination. These results make up the entries of the routing matrix.

To be able to calculate matrices with origins and destinations of arbitrary length, one of the supported profiles needs to be selected in the request. The special variant world needs to be set as region definition. No additional request options or departure time can provided except for matrixAttributes.

Below is 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 quadratic 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 like this: Matrix Request in Europe

The full procedure of submitting a matrix request is described in the Send a Request section. The response looks like this:

{
    "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

results matching ""

    No results matching ""