Calculating Toll for a Route

This article explains how to calculate the toll price of a routeA route corresponds to a path of a vehicle through the underlying transport network. The main attributes of a route are the distance and the time that the vehicle travels along the path..

Benefits

Prerequisites

Configuration

The sections result field is set automatically. The general toll result field to retrieve at least the summary is always set to true.

Programming Guide

Here is an example for the calculation of toll. The function determineTollDetails sends a request to dataInformation and extracts the following information:

var referenceTime = "2019-05-13T10:00:10+01:00"; var hasDetailedToll = false; var etcSubscriptions = "NONE"; // Determine the toll detail level and get the available values for the electronic toll collection subscriptions function determineTollDetails() { var urlPath = xServerUrl + '/services/rest/XRuntime/experimental/dataInformation'; $.ajax(urlPath).always(function(response){ if (response) { if (response.mapFeatures.tollFeatures) { if (response.mapFeatures.tollFeatures.detailLevel == "DETAILED" || response.mapFeatures.tollFeatures.detailLevel == "MIXED") { hasDetailedToll = true; } if (response.mapFeatures.tollFeatures.electronicTollCollectionSubscriptions) { etcSubscriptions = response.mapFeatures.tollFeatures.electronicTollCollectionSubscriptions; noneIdx = etcSubscriptions.indexOf('NONE'); if (noneIdx >= 0) { etcSubscriptions.splice(noneIdx, 1); } etcSubscriptions = etcSubscriptions.toString(); } } } }); }; determineTollDetails(); var A = { "$type": "OffRoadWaypoint", "location": { "offRoadCoordinate": { "x": -71.4425823, "y": 41.5492741 } } }; var B = { "$type": "OnRoadWaypoint", "location": { "coordinate": { "x": -71.3055992, "y": 41.5010570 } } }; xroute.calculateRoute({ "storedProfile": "truck11_99t.xml", "requestProfile": { "vehicleProfile": { "electronicTollCollectionSubscriptions": etcSubscriptions, } }, "waypoints": [A, B], "routeOptions": { "timeConsideration": { "$type": "ExactTimeConsiderationAtStart", "referenceTime": referenceTime }, "tollOptions": { "useDetailedToll": hasDetailedToll } }, "resultFields": { "toll": { "enabled": true, "sections": hasDetailedToll } } }, routingCompleted); function routingCompleted(route, exception) { var result = route.distance + 'm in ' + route.travelTime + 's,'; if (route.toll.summary && route.toll.summary.costs && route.toll.summary.costs.length > 0) { result += ' total toll price '; for (costIdx = 0; costIdx < route.toll.summary.costs.length; costIdx++) { result += route.toll.summary.costs[costIdx].amount + ' ' + route.toll.summary.costs[costIdx].currency; if (costIdx + 1 < route.toll.summary.costs.length) result += ', '; } if (route.toll.sections) { result += ' summed up over ' + route.toll.sections.length + ' section(s)'; var numberOfPrices = 0; for (sectionIdx = 0; sectionIdx < route.toll.sections.length; sectionIdx++) { if (route.toll.sections[sectionIdx].alternativeCosts) numberOfPrices += route.toll.sections[sectionIdx].alternativeCosts.length; } result += ' with ' + (1 + numberOfPrices) + ' different price(s)'; } } else result += ' WITHOUT toll. If you are running the unmodified example check the prerequisites and configuration above.'; print(result); }

Related Topics

The following topics might be relevant for this use case.