Toll for Maps

Example 2 – Tolls by time slot

Some toll plazas, especially in Argentina and Chile, have prices that vary according to the day, time or season of the year the route is being traveled.

In Argentina, for example, concessionaires have special rates for peak times, weekends and public holidays, or specific times of the year such as low season and high season.

Below is the tariff table for Argentina’s AUSA concessionaire, which offers two types of tariff, one for regular hours and one for peak hours.

In Brazil, this type of tariff is rarer, but some concessionaires already charge different values on weekends and public holidays

In this example we have a route with a 4-axle truck that will pass through the Sarmiento toll in Argentina. According to the table above, this toll has conditional values for peak hours.

The request made to the Directions API can be seen below:

https://maps.googleapis.com/maps/api/directions/json?origin=-23.465395,-46.375007&waypoints=-23.465957,-46.371015&destination=-23.467154, -46.365598&mode=driving&key={API_KEY}

Below is the request to the Toll for Maps API, where the response from Directions will be sent in the body of the request to the https://api.maplink.global/toll/v1/directions endpoint, as in the example below:

curl -X POST "https://api.maplink.global/toll/v1/directions?vehicleType=TRUCK_WITH_FOUR_DOUBLE_AXLES" -H "Authorization: Bearer 3O0d0YjOL72Roqp5CrnGwh5yvgKH" -H "Content-Type: application/json" -d @C:\temp\Directions_Response.json

Where:

  • vehicleType – Type of vehicle calculating the toll;
  • Directions_Response.json – Directions API response containing the route.

The result can be seen on the map below:

The response will come in JSON format.

The tolls for each route will be obtained from results.

If the Directions API is processed with alternative routes, it will return 3 results, with 1 result for each route.

Within each results an object legs will be returned which corresponds to the route itself. The object will contain the total value of the route at totalCost and an object tolls with the values and information for each toll on the route.

Inside each object at tolls we will have the information for each toll. With the following differences:

  • price – Normal toll in local currency, charged at off-peak times or any other condition;
  • conditions – Array com todos os valores condicionais do pedágio. Informa se há  variações de preços devido alguma condição de dia da semana, horário e se é realizado com pagamento automático ou manual. No caso desse exemplo, temos as seguintes informações:
    • daysOfWeek – Array with the days of the week to which the rate applies. The possible values are: [MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]
    • subConditions – Indicates subconditions for the day of the week to which the tariff applies;
      • periods – Array with the periods in which the rate applies on the day of the week. In this example, there is the period "NORMAL" and the period "HOLIDAY". The possible values are: [NORMAL, HOLIDAY, LOW_SEASON, HIGH_SEASON].
      • timesWindow – Array with the time intervals in["HH:mm:ss = HH:mm:ss"] format.
      • billingsType – Type of toll collection. Possible values: [NORMAL, TAG];
      • value – Toll value in local currency.

The full response can be found below:

{
    "id": "658084734d0aa15a056e8f31",
    "clientId": "maplink",
    "totalDistance": 327,
    "totalNominalDuration": 31,
    "averageSpeed": 52.00,
    "tollCosts": 508.03,
    "legs": [
        {
            "distance": 327,
            "nominalDuration": 31,
            "averageSpeed": 52.0,
            "points": "zh~qEfpncJJ]HM\\Q\\C^LRTJb@@RAVOj@?XS\\aDvF",
            "tollCalculation": {
                "tolls": [
                    {
                        "id": "1032",
                        "name": "Pórtico - Sarmiento",
                        "address": "Avenida Sarmiento, 4254",
                        "city": " ",
                        "state": {
                            "name": "Ciudad Autonoma de Buenos Aires",
                            "code": "Ciudad Autonoma de Buenos Aires"
                        },
                        "country": "Argentina",
                        "concession": "Ausa",
                        "direction": "WEST",
                        "coordinates": {
                            "latitude": -34.5671991,
                            "longitude": -58.4063059
                        },
                        "serviceTypes": [],
                        "price": 508.03,
                        "conditions": [
                            {
                                "daysOfWeek": [
                                    "MONDAY",
                                    "TUESDAY",
                                    "WEDNESDAY",
                                    "THURSDAY",
                                    "FRIDAY"
                                ],
                                "subConditions": [
                                    {
                                        "periods": [
                                            "NORMAL"
                                        ],
                                        "subConditions": [
                                            {
                                                "timesWindow": [
                                                    "16:00:00 - 19:59:59",
                                                    "07:00:00 - 10:59:59"
                                                ],
                                                "subConditions": [
                                                    {
                                                        "billingsType": [
                                                            "NORMAL"
                                                        ],
                                                        "value": 1221.56
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "daysOfWeek": [
                                    "SUNDAY",
                                    "SATURDAY"
                                ],
                                "subConditions": [
                                    {
                                        "periods": [
                                            "NORMAL"
                                        ],
                                        "subConditions": [
                                            {
                                                "timesWindow": [
                                                    "17:00:00 - 20:59:59"
                                                ],
                                                "subConditions": [
                                                    {
                                                        "billingsType": [
                                                            "NORMAL"
                                                        ],
                                                        "value": 1221.56
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "daysOfWeek": [
                                    "MONDAY",
                                    "TUESDAY",
                                    "WEDNESDAY",
                                    "THURSDAY",
                                    "FRIDAY",
                                    "SUNDAY",
                                    "SATURDAY"
                                ],
                                "subConditions": [
                                    {
                                        "periods": [
                                            "HOLIDAY"
                                        ],
                                        "subConditions": [
                                            {
                                                "timesWindow": [
                                                    "17:00:00 - 20:59:59"
                                                ],
                                                "subConditions": [
                                                    {
                                                        "billingsType": [
                                                            "NORMAL"
                                                        ],
                                                        "value": 1221.56
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ],
                "legTotalCost": 508.03,
                "vehicleType": "TRUCK_WITH_FOUR_DOUBLE_AXLES"
            }
        }
    ],
    "source": "MAPLINK"
}