Distance Matrix

Example 2 – Finding the nearest vehicle assistance

In the vehicle insurance industry, it is very common to use the Distance Matrix API to reduce vehicle assistance service times.

Since the broken-down vehicle and the tow trucks share a latitude/longitude location, when the broken-down vehicle calls for assistance, the system can use the Distance Matrix API to decide which tow truck will arrive first.

In this example, the destination is two broken-down vehicles and the origin is five tow trucks:

{
    "calculationMode": "THE_FASTEST",
    "destinations": [
        {
            "latitude": -23.5654032,
            "longitude": -46.62117004,
            "siteId": "veiculo1-Cambuci"
        },
        {
            "latitude": -23.574136,
            "longitude": -46.655844,
            "siteId": "veiculo2-Jardins"
        }
    ],
    "origins": [
        {
            "latitude": -23.58664317,
            "longitude": -46.63833618,
            "siteId": "guincho1-VilaMariana"
        },
        {
            "latitude": -23.562412,
            "longitude": -46.638788,
            "siteId": "guincho2-Liberdade"
        },
        {
            "latitude": -23.55363650451996,
            "longitude": -46.620810158377516,
            "siteId": "guincho3-Mooca"
        },
        {
            "latitude": -23.561603,
            "longitude": -46.655840,
            "siteId": "guincho4-MASP"
        },
        {
            "latitude": -23.535016,
            "longitude": -46.735701,
            "siteId": "guincho5-CEAGESP"
        }
    ],
    "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, the distance between each winch and vehicle will be returned. This way you can identify which tow truck will be able to provide assistance quickly.

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": "60761bd2b966b04b48d1019c",
    "clientId": "maplink",
    "elements": [
        {
            "origin": "guincho1-VilaMariana",
            "destination": "veiculo1-Cambuci",
            "distance": 3569,
            "nominalDuration": 643,
            "averageSpeed": 19.98
        },
        {
            "origin": "guincho1-VilaMariana",
            "destination": "veiculo2-Jardins",
            "distance": 3711,
            "nominalDuration": 365,
            "averageSpeed": 36.6
        },
        {
            "origin": "guincho2-Liberdade",
            "destination": "veiculo1-Cambuci",
            "distance": 4209,
            "nominalDuration": 514,
            "averageSpeed": 29.48
        },
        {
            "origin": "guincho2-Liberdade",
            "destination": "veiculo2-Jardins",
            "distance": 3710,
            "nominalDuration": 336,
            "averageSpeed": 39.75
        },
        {
            "origin": "guincho3-Mooca",
            "destination": "veiculo1-Cambuci",
            "distance": 2787,
            "nominalDuration": 426,
            "averageSpeed": 23.55
        },
        {
            "origin": "guincho3-Mooca",
            "destination": "veiculo2-Jardins",
            "distance": 5265,
            "nominalDuration": 490,
            "averageSpeed": 38.68
        },
        {
            "origin": "guincho4-MASP",
            "destination": "veiculo1-Cambuci",
            "distance": 6842,
            "nominalDuration": 859,
            "averageSpeed": 28.67
        },
        {
            "origin": "guincho4-MASP",
            "destination": "veiculo2-Jardins",
            "distance": 2082,
            "nominalDuration": 305,
            "averageSpeed": 24.57
        },
        {
            "origin": "guincho5-CEAGESP",
            "destination": "veiculo1-Cambuci",
            "distance": 15608,
            "nominalDuration": 1588,
            "averageSpeed": 35.38
        },
        {
            "origin": "guincho5-CEAGESP",
            "destination": "veiculo2-Jardins",
            "distance": 11217,
            "nominalDuration": 1057,
            "averageSpeed": 38.2
        }
    ],
    "createdAt": 1618353108108
}

In a tabular view of the result, it is possible to conclude the following:

  1. The vehicle "veiculo1-Cambuci" will receive faster and closer service from the tow truck "guincho3-Mooca";
  2. The vehicle "veiculo2-Jardins" will receive faster and closer service from the tow truck "guincho4-MASP".
origindestinationdistancenominalDurationaverageSpeed
guincho1-VilaMarianaveiculo1-Cambuci356964319.98
guincho2-Liberdadeveiculo1-Cambuci420951429.48
guincho3-Moocaveiculo1-Cambuci278742623.55
guincho4-MASPveiculo1-Cambuci684285928.67
guincho5-CEAGESPveiculo1-Cambuci15608158835.38
guincho1-VilaMarianaveiculo1-Jardins371136536.6
guincho2-Liberdadeveiculo1-Jardins371033639.75
guincho3-Moocaveiculo1-Jardins526549038.68
guincho4-MASPveiculo1-Jardins208230524.57
guincho5-CEAGESPveiculo1-Jardins11217105738.2
Result of the request organized in a table