Recalculate toll and emissions

You can calculate toll or emissions for a driven route if you combine the PTV Developer Map Matching API and PTV Developer Routing API. You can use this for compliance measurements like a toll cost validation.

The following steps describe how to recalculate a driven route by using a matched track in order to get toll costs and/or emissions.

1. Create a matched track

Use the createMatchedTrack endpoint to create a track and therefor start a track matching calculation.

The following POST request creates a track and starts the matching calculation:

https://api.myptv.com/mapmatch/v1/tracks?apiKey=YOUR_API_KEY

The JSON body of the request contains the input positions:

{
    "positions": [
    {
        "latitude": 49.859847782841,
        "longitude": 2.209582931400154
    },
    {
        "latitude": 49.85829914753867,
        "longitude": 2.2206529522238054
    },
    {
        "latitude": 49.84861368112285,
        "longitude": 2.2405862648194175
    },
    {
        "latitude": 49.85154557212113,
        "longitude": 2.2458638328865015
    },
    {
        "latitude": 49.85505457921637,
        "longitude": 2.2530220746794565
    }
]
}

If the request succeeds, the response contains an ID. Using this ID you can request the results of the match track calculation:

{
    "id": "1e05ad60-35c1-48f9-be4d-1ead39b3d0c6"
}
2. Get the matched track

With a GET request to the getMatchedTrack endpoint you can fetch the results of the calculation. Therefor you have to provide the ID of the createMatchedTrack response as path parameter. The following request only returns the results that are necessary for the toll or emission calculation (PATHS and ROUTE_ID). The route ID and the geometry of the corresponding matched track is stored in the background to access it later via the Routing API.

https://api.myptv.com/mapmatch/v1/tracks/1e05ad60-35c1-48f9-be4d-1ead39b3d0c6?results=PATHS,ROUTE_ID&apiKey=YOUR_API_KEY

If the request was successful the response looks like this:

{
    "status": "SUCCEEDED",
    "matchedTrack": {
        "id": "1e05ad60-35c1-48f9-be4d-1ead39b3d0c6",
        "distance": 4701,
        "paths": [
            {
                "distance": 4701,
                "startTrackPositionIndex": 0,
                "endTrackPositionIndex": 4,
                "routeId": "16e8eb5a-0e0b-4493-a01b-f56b9bbdd2f2"
            }
        ]
    }
}
3. Recalculate the matched track with the Routing API

With a GET request to the calculateRoute endpoint of the Routing API you can recalculate the matched track. Therefor you have to provide the route ID of the getMatchedTrack response as query parameter to the request. When using the route ID of a matched track in a routing request, the geometry of the matched track is fetched from the storage in the background. The Routing API then uses the matched track geometry to recalculate the driven route.

 
Calculate toll

Calculating toll requires to request the TOLL_COSTS result:

https://api.dev.myptv.com/routing/v1/routes?routeId=6912c1b1-f31b-4e34-b006-4a3d41f8e24f&results=TOLL_COSTS&apiKey=YOUR_API_KEY

If the request was successful the response containig the toll costs for the matched track looks like this:

{
    "distance": 4701,
    "travelTime": 321,
    "trafficDelay": 0,
    "violated": false,
    "toll": {
        "costs": {
            "prices": [
                {
                    "price": 2.25,
                    "currency": "EUR"
                }
            ],
            "countries": [
                {
                    "countryCode": "FR",
                    "price": {
                        "price": 2.25,
                        "currency": "EUR"
                    }
                }
            ]
        }
    }
}
 
Calculate emissions

Similar to the toll calculation, you can calculate the emissions using one of the emission schemes. For this, the route ID is again used as input parameter. Please be aware that the route ID is stored for 60 minutes only.

https://api.dev.myptv.com/routing/v1/routes?routeId=6912c1b1-f31b-4e34-b006-4a3d41f8e24f&results=EMISSIONS_EN16258_2012_HBEFA&apiKey=YOUR_API_KEY

If the request was successful the response containig the emissions for the matched track looks like this:

{
    "distance": 4701,
    "travelTime": 321,
    "trafficDelay": 0,
    "violated": false,
    "emissions": {
        "en16258_2012": {
            "fuelConsumption": 0.14324482439878058,
            "co2eTankToWheel": 0.4596919244528175,
            "co2eWellToWheel": 0.5578284027067898,
            "energyUseTankToWheel": 6.180876437399306,
            "energyUseWellToWheel": 7.351627406043187
        }
    }
}