トールのコスト拡張
トールコスト拡張 機能を使用すると、 HERE SDK からトールコスト拡張 API に簡単にアクセスできます。 HERE トール コスト拡張( TCE )を使用すると、定義された車両プロファイルの特定のルートのトールコストを判断できます。
TCE クラス
クラス | 説明 |
---|---|
[NMAATollCostOptions] | ルート、車両プロファイル、通貨、出発日を含むトールコスト計算のすべてのパラメータ。 [NSObject description] メソッドを実装します。 |
NMAATollCostRequest | トールコストデータの TCE リクエストを作成します。 |
NMAATollCostResult | TCE データ要求の実行後、このクラスで結果が返されます。 |
NMAATollCostVehicleProfile | 使用する車両のすべてのパラメータ。 [NSObject description] メソッドを実装します。 |
トールコストデータを要求しています
トールコスト拡張を使用するには、トールコスト拡張に永続的なダイレクトリンク ID が必要なため、まずオンラインモードでルートを計算する必要があります。 コアルータからルートを取得した後、ルートのトールコストを取得できます。
// Create the core router
NMACoreRouter *coreRouter = [[NMACoreRouter alloc] init];
// We need link IDs, NMARoute.permanentDirectedLinkIds, so we force online routing
coreRouter.connectivity = NMACoreRouterConnectivityOnline;
のインスタンスを使用して、トールコストリクエストのオプションを指定 NMATollCostOptions
できます。 このトールリクエストが特定のタイプの車両に対するものである場合など、車両にデフォルト以外の設定が必要な場合 NMATollCostVehicleProfile
は、オブジェクトを作成します。
次に NMATollCostRequest
、リクエストオブジェクトを作成します。 リクエストオブジェクトが有効で、ルートに永続的なダイレクトリンク ID が含まれている場合は、ブロックまたはリスナーを介してトールコストリクエストを実行できます。 結果が受信されると、まずエラーがないか確認されます。 エラーがない場合は、そのトールコストの内容が取得されます。

// 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!");
}