SDK for iOS Developer's Guide

Truck Routing

The Truck Routing feature in HERE SDK allows users to calculate routes that can be specifically travelled by trucks and commercial vehicles. Commercial vehicles typically have different regulations for their transportation routes. For example, a government may have laws that restrict trucks carrying flammable materials from travelling in a residential area. By using the Truck Routing feature, you can launch a route calculation that specifically adheres to these restrictions.

In order to perform offline truck routing, you have to download or prefetch optional data group NMAMapDataGroupTruckAttributes such as in the example below. For more information about Data Groups refer to Map Package Download.

// Select additional data group needed for offline truck routing
[[NMAMapLoader sharedMapLoader] selectDataGroup:NMAMapDataGroupTruckAttributes];
// Whether download map package(s)
[[NMAMapLoader sharedMapLoader] installMapPackages:@[package]];
// Or prefetch map data
[[NMAMapDataPrefetcher sharedMapDataPrefetcher] fetchMapDataForRoute:route radius:radius error:&error];

Truck Routing and the NMARoutingMode class

The NMARoutingMode class contains truck-specific properties that you should set to perform a route calculation. You need to set the route transportation mode to NMATransportModeTruck and then optionally set the following route properties before launching the calculation:
  • The number of truck trailers
  • The truck height
  • The truck length
  • The truck width
  • The maximum allowed truck weight
  • The category of tunnels that the truck cannot travel on
  • The truck weight per axle
  • Hazardous goods that are transported by the truck
  • Difficult turns
Note: Truck routing only supports NMARoutingTypeFastest. Other routing types are not supported.

A Route Calculation Example

  1. As with the previous routing example, create the NMACoreRouter, then create an NSArray and set its waypoints.
  2. Initialize NMARoutingMode and set the transport mode to NMATransportModeTruck.
    NMARoutingMode* routingMode = [[NMARoutingMode alloc] initWithRoutingType:NMARoutingTypeFastest transportMode:NMATransportModeTruck routingOptions:0];
    
  3. Set other truck routing properties.
    routingMode.vehicleLength = 25.25f;
    routingMode.vehicleHeight = 2.6f;
    routingMode.trailersCount = 1;
    
  4. Calculate the route by calling calculateRouteWithStops:routingMode:completionBlock:.
    [coreRouter calculateRouteWithStops:stops routingMode:routingMode
        completionBlock:^(NMARouteResult *routeResult, NMARoutingError error) {
          // If the route was calculated successfully
          if (!error && routeResult && routeResult.routes.count > 0)
          {
            NMARoute* route = [routes objectAtIndex:0];
            // Render the route on the map
            mapRoute = [NMAMapRoute mapRouteWithRoute:route];
            [mapView addMapObject:mapRoute];
          }
          else if(error)
          {
            // Display a message indicating route calculation failure
          }
        }];