Calculating Toll for a Matched Track
In combination with PTV xRoute Service, compliance measurements like a toll cost validation can be executed.
Benefits
- Comparison between calculated and billed toll costs
Prerequisites
Please ensure following prerequisites are fulfilled before you start with the use case:
- Installed and licensed PTV xMatch Service
- Installed map that contains toll data
Programming Guide
The following sample illustrates the basic steps that are necessary to match a GPS track with the matchTrack and calculate its toll costs with calculateRoute.
var map = new L.Map('map', {
center: [49.61, 6.125],
zoom: 13
});
// Add tile layer to map
var tileUrl = xServerUrl + '/services/rest/XMap/tile/{z}/{x}/{y}';
var tileLayer = new L.TileLayer(tileUrl, {
minZoom: 3,
maxZoom: 18,
noWrap: true
}).addTo(map);
var outputString='';
function matchTrack(track) {
xmatch.matchTrack({
"trackPositions": track,
"resultFields": {
"matchedPaths": true,
"geometry": true,
"encodedPath": true
},
"geometryOptions": {
"responseGeometryTypes": ["GEOJSON"]
}
}, function(response, exception) {
displayGeoJson(response.geometry.geoJSON);
calculateToll(response.matchedPaths[0].encodedPath)
});
}
function calculateToll(encodedPath) {
xroute.calculateRoute({
"waypoints": [
{
"$type": "PathWaypoint",
"encodedPath" : encodedPath
}
],
"resultFields": {
"eventTypes": [
"TOLL_EVENT"
],
"toll": {
"enabled": true,
"sections": true,
"systems": true
}
},
"routeOptions": {
"tollOptions": {
"useDetailedToll": true
}
},
"requestProfile": {
"routingProfile": {
"course": {
"toll": {
"tollPenalty": 0
}
}
},
"vehicleProfile": {
"electronicTollCollectionSubscriptions": "NONE"
}
},
"storedProfile": "truck11_99t"
}, function(response, exception) {
print("The toll costs for the track are " + response.toll.summary.costs[0].amount + " " + response.toll.summary.costs[0].currency + ".");
});
}
function displayGeoJson(geoJson) {
var jsonObject = JSON.parse(geoJson);
var geoJsonLayer = new L.GeoJSON(jsonObject, {
style: {
color: '#2882C8',
weight: 8
}
}).addTo(map);
map.fitBounds(geoJsonLayer.getBounds());
};
var track = [
{
"coordinate": {
"x": -71.368186645,
"y": 41.524117624
}
}, {
"coordinate": {
"x": -71.366889047,
"y": 41.511746246
}
}, {
"coordinate": {
"x": -71.364207345,
"y": 41.508572056
}
}, {
"coordinate": {
"x": -71.341110105,
"y": 41.503259798
}
}, {
"coordinate": {
"x": -71.323246509,
"y": 41.499437294
}
}, {
"coordinate": {
"x": -71.317883104,
"y": 41.500862661
}
}, {
"coordinate": {
"x": -71.316109721,
"y": 41.505430103
}
}, {
"coordinate": {
"x": -71.313081993,
"y": 41.50821576
}
}, {
"coordinate": {
"x": -71.31290898,
"y": 41.50779468
}
}];
matchTrack(track);
Related Topics
The following topics might be relevant for this use case.