Distance Matrix

Example 1 – Calculating the distance matrix between three points

In this example, a matrix of distances between a point of origin and two points of destination will be calculated. It will be possible to apply optional parameters such as avoiding tunnels and bridges and choosing the calculation mode for the fastest route.

{
    "avoidanceTypes": [
        "TUNNELS",
        "BRIDGES"
    ],
    "calculationMode": "THE_FASTEST",
    "destinations": [
        {
            "latitude": -23.682211,
            "longitude": -46.546867,
            "siteId": "SantoAndre"
        },
        {
            "latitude": -23.561402303338195, 
            "longitude": -46.63862145421187,
            "siteId": "SP-Liberdade"
        }
    ],
    "origins": [
        {
            "latitude": -23.337132,
            "longitude": -46.835427,
            "siteId": "Cajamar"
        }
    ],
    "restrictionZones": [],
    "tripProfile": "MAPLINK"
}

The response returns the array of objects elements, where each object represents the relationship between each source and destination pair. In this case from Cajamar to SantoAndre and Cajamar to SP-Liberdade.

Each object on elements will have the following information:

  • origin – Origin point identifier;
  • destination – Identifier of the destination point;
  • distance – Total distance in meters;
  • nominalDuration – Total duration in seconds;
  • averageSpeed – Average speed of the route between origin and destination in km/h.

The full response can be found below:

{
    "id": "6076163ab966b04b48d1017c",
    "clientId": "maplink",
    "elements": [
        {
            "origin": "Cajamar",
            "destination": "SantoAndre",
            "distance": 253569,
            "nominalDuration": 32617,
            "averageSpeed": 27.99     
        },
        {
            "origin": "Cajamar",
            "destination": "SP-Liberdade",
            "distance": 286385,
            "nominalDuration": 35963,
            "averageSpeed": 28.67            
        }
    ],
    "createdAt": 1618351678886
}