Toll Cost Extension
Toll Cost Extension provides you 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 |
---|---|
TollCostOptions | Specify all input parameters of TollCostRequest which include vehicle profile currency and departure date. |
TollCostRequest | Allows you to determine the toll costs for a specified route for a defined vehicle profile. |
TollCostResult | Represents a result from a TCE request. |
TollCostVehicleProfile | Specify different vehicle parameters and optional input parameters. |
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 getting a route from the core router, you can then retrieve the toll cost of the route.
// Create the core router
CoreRouter router = new CoreRouter();
// We need link IDs, Route.getPermanentLinkIds(), so we force online routing
router.setConnectivity(Connectivity.ONLINE);
You can provide options for the toll cost request through an instance of TollCostOptions
. If the vehicle needs non-default settings, e.g. if this toll request is for a specific type of vehicle, create a TollCostVehicleProfile
object.
Next, create a TollCostRequest
request object. If the request object is valid and the route contains permanent directed link ids, then you can execute the toll cost request via a result listener. When the result is received, first it is checked for any error. If there is no error, its toll cost contents are retrieved.

// Step 1: Provide input and calculate toll cost.
Route route = null; // Required
Date departureTime = null; // Optional
// Step 2: Wrap all input.
// Vehicle profile -> Type Bus, EmissionType EURO_IV, TrailerType NONE. Optional.
TollCostVehicleProfile vehicleProfile = new TollCostVehicleProfile();
vehicleProfile.setVehicleType(TollCostVehicleProfile.VehicleType.BUS);
vehicleProfile.setEmissionType(TollCostVehicleProfile.EmissionType.EURO_IV);
vehicleProfile.setTrailerType(TollCostVehicleProfile.TrailerType.NONE);
TollCostOptions options = new TollCostOptions();
options.setDeparture(departureTime);
options.setVehicleProfile(vehicleProfile);
// Step 3: Create request
TollCostRequest request = new TollCostRequest(route, options); // request created, can not be modify.
// Step 4: Execute with result listener
request.execute(new TollCostRequest.Listener<TollCostResult>() {
@Override
public void onComplete(TollCostResult result, TollCostError error) {
// Step 5: process result
if(error.getErrorCode() != TollCostError.ErrorCode.SUCCESS) {
// what is the error?
error.getErrorMessage();
return;
}
// if success
// get total toll cost of a route
result.getTotalTollCost();
// get toll cost by country
java.util.Map<String, Double> tollCostByCountry = result.getTollCostByCountry();
// get toll cost by toll system name
java.util.Map<String, Double> tollCostByTollSystem = result.getTollCostByTollSystemName();
}
});