SDK for Android Developer's Guide

Truck Routing

The Truck Routing feature in HERE SDK allows users to calculate routes that can be specifically utilized 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 traveling 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 TruckAttributes 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
MapLoader.getInstance().selectDataGroup(MapPackage.SelectableDataGroup.TruckAttributes);
// Whether download map package(s)
MapLoader.getInstance().installMapPackages(packageIdList);
// Or prefetch map data
MapDataPrefetcher.Request req = MapDataPrefetcher.getInstance().fetchMapData(area);

Truck Routing and the RouteOptions Class

The RouteOptions class contains a number of truck-specific methods and enums that you should use before performing a route calculation. To perform a truck route calculation, use the TransportMode.TRUCK enum with setTransportMode(TransportMode) method to specify the route transportation type. You can also set the following truck-specific route options before performing the route calculation:
  • The number of truck trailers
  • The truck height
  • The truck length
  • The truck width
  • The maximum allowed truck weight
  • Hazardous goods transported by the truck
  • The category of tunnels that the truck can travel through
  • The truck weight per axle
  • Difficult turns
Note: Truck routing only supports RouteOptions.Type.FASTEST routing type. Other routing types are not supported.

A Route Calculation Example

  1. As with the previous routing example retrieve the CoreRouter, create a RoutePlan and set its waypoints.
  2. Create a new RouteOptions object. The TransportMode should be set to TRUCK.
    // Create the RouteOptions and set its transport mode & routing type
    RouteOptions routeOptions = new RouteOptions();
    routeOptions.setTransportMode(RouteOptions.TransportMode.TRUCK);
    routeOptions.setRouteType(RouteOptions.Type.FASTEST);
    
  3. Set other truck routing options.
    routeOptions.setTruckTunnelCategory(TunnelCategory.E)
      .setTruckLength(25.25f)
      .setTruckHeight(2.6f)
      .setTruckTrailersCount(1);
    
  4. Set the RouteOptions to the RoutePlan.
    routePlan.setRouteOptions(routeOptions);
    
  5. Create a CoreRouter.Listener and then calculate the route by calling CoreRouter.calculateRoute(RoutePlan, Listener).