Toll Cost Extension
Toll Cost Extension provides you with the possibility to easily access Toll Cost Extension API from HERE SDK. HERE Toll Cost Extension (TCE) allows you to determine the toll costs for a specified route for a defined vehicle profile.
TCE Classes
Class | Description |
---|---|
NMATollCostOptions | All parameters for the toll cost calculation including route, vehicle profile, currency, and departure date. It implements [NSObject description] method. |
NMATollCostRequest | Creates the TCE request for the toll cost data. |
NMATollCostResult | After a TCE data request run the result is returned with this class. |
NMATollCostVehicleProfile | All parameters of the vehicle to be used. It implements [NSObject description] method. |
Requesting the Toll Cost Data
To use Toll Cost Extension, you need to first have a route calculated in online mode as the Toll Cost Extension requires permanent directed link IDs. After having a route from the core router, you can then retrieve the toll cost of the route.
// Create the core router
NMACoreRouter *coreRouter = [[NMACoreRouter alloc] init];
// We need link IDs, NMARoute.permanentDirectedLinkIds, so we force online routing
coreRouter.connectivity = NMACoreRouterConnectivityOnline;
You can provide options for the toll cost request through an instance of NMATollCostOptions
. If the vehicle needs non-default settings, such as if this toll request is for a specific type of vehicle, create an NMATollCostVehicleProfile
object.
Next, create an NMATollCostRequest
request object. If the request object is valid and the route contains permanent directed linkids, then you can execute the toll cost request via a block or a listener. When the result is received, first it is checked for any errors. If there are no errors, its toll cost contents are retrieved.

// Step 1: Get the input
// Mandatory. Assume it is calculated via the above core router for a truck.
NMARoute route;
// Optional. Set it to the date and time for the trip
NSDate departureTime;
NMATollCostVehicleProfile *vehicleProfile = [[NMATollCostVehicleProfile alloc] init];
vehicleProfile.tollVehicleType = NMATollCostVehicleTypeTruck;
vehicleProfile.trailerType = NMATollCostTrailerTypeNone;
vehicleProfile.trailersCount = NMATollCostTrailersCountNone;
vehicleProfile.vehicleNumberAxles = 2;
vehicleProfile.emissionType = NMATollCostEmissionTypeEuroVI;
vehicleProfile.hybridType = NMATollCostHybridTypeNone;
vehicleProfile.height = 3.8f;
vehicleProfile.vehicleWeight = 11.0f;
vehicleProfile.limitedWeight = 11.0f;
vehicleProfile.passengersCount = 1;
vehicleProfile.tiresCount = 4;
vehicleProfile.commercial = true;
vehicleProfile.shippedHazardousGoods = NMATollCostShippedHazardousGoodsNone;
vehicleProfile.heightAbove1stAxle = 1.0f;
// Step 2: Wrap all the input
NMATollCostOptions *options = [NMATollCostOptions alloc] initWithVehicleProfile:route];
parameter.departure = departureTime; // Optional
parameter.currency = @"USD"; // Optional
// Step 3: Create the TCE request
NMATollCostRequest request = [[NMATollCostRequest alloc] initWithRoute:route andOptions:options];
// Step 4: Execute the TCE request with a block
// Is the request valid?
if (request) {
[request startWithBlock:^(NMATollCostRequest *request, NMATollCostResult *result, NSError *error) {
if (error) {
// Something has gone wrong
NSLog(@"Error occurred!\n"
"Code: %ld\n"
"Description: %@\n",
(long)error.code,
error.localizedDescription];
} else {
// Retrieved the result successfully
// What is the total toll cost?
NSString *tollCost = [NSString stringWithFormat:@"%.2f", result.tollCost.doubleValue];
NSLog(@"Total Toll Cost: %@ %@\n", tollCost, options.currency];
// What is the toll cost per country along the route?
NSDictionary<NSString*, NSString*> *countryTollMap = result.tollCostByCountry;
for (NSString *country in countryTollMap) {
NSlog(@"Country: %@ -> Toll Cost: %@\n", country, countryTollMap[country]);
}
// What is the toll cost per toll system along the route?
NSDictionary<NSString*, NSString*> *tollSystemMap = result.tollSystemMap;
for (NSString *system in tollSystemMap) {
NSlog(@"Toll System: %@ -> Toll Cost: %@\n", system, tollSystemMap[system]);
}
}
}];
} else {
NSLog(@"Invalid request!");
}