Hands On

Truck Routing with the HERE Fleet Telematics APIs

By Shruti Kuber | 15 March 2019

In a world of same-day deliveries, hyper-precise logistics are a standard, not a luxury. In this series, I will be pulling the curtain and showing you how you can utilize the HERE Fleet Telematics APIs to create applications for solving the specific needs of vehicles in logistics. The first part in this series is truck routing.

Before a shipment lands at our doorstep, we often forget the long distances it traveled across cities, countries or even the entire globe. Moreover, the journey of a package involves trucks, motorways, roads with restrictions, as well as busy city roads. Logistics companies spend a lot of time and energy to schedule these deliveries and have to take into consideration numerous factors like availability of vehicles, location, traffic, malfunctions etc.

While it is obvious that a car and a truck are different in many ways, the nuances between car and truck routing are often neglected which leave the truck drivers frustrated. Road restrictions on truck height, material carried, variable toll costs, and tunnels are a few of the many constraints to take into account for navigation of trucks. This leaves a great opportunity to create applications focusing on Truck Navigation. In this article, we will cover truck routing, and road restrictions that consider truck height, weight, trailer count, tunnels and the material that the trucks carry (hazardous material).

While discussing the Truck Routing API, I would like to discuss 3 distinct attributes : Route Mode, Truck Type, Truck Profile. Let's get into them one by one. To begin with, get your HERE credentials and get access to the developer portal. I have followed the routing example to set up an application which routes between two cities using the default car navigation which is written using the JavaScript API. You can also check out our Android SDK, iOS SDK and REST API.

Mode:

To observe the difference between car and truck navigation, change the mode in the routeRequestParameters to Truck.

  
function calculateRouteFromAtoB (platform) {
    var router = platform.getRoutingService(),
      routeRequestParams = {
        mode: 'fastest;truck;',
        representation: 'display',
        routeattributes : 'no,lg',
        RouteLegAttributeType: 'wp,mn',
        maneuverattributes: 'direction,action',
        waypoint0: '51.0535,13.74079', 
        waypoint1: '54.07906,12.13216',  
      };

    router.calculateRoute(
      routeRequestParams,
      onSuccess,
      onError
    );
  }
Route with CarRoute with Car
Route with TruckRoute with Truck

You can clearly see the difference in the two routes. The routing API can be described in the format Routing Type;Transport Mode; Traffic Mode;Route Feature.

In the code snippet above, the type of route requested is fastest. Depending on the requirement, it can be set to shortest or balanced (optimizes based on combination of travel time and distance). The transport mode here is set to truck. Depending on your application, it can be set to car, publicTransport, pedestrian, etc. The traffic mode can be enabled or disabled indicating whether traffic information is to be considered. Adding the start timing to the route request can give you different routes considering peak times in traffic. The route feature lets you choose a route with or without tunnels, if it can include motorways, dirt roads, tolls etc. You can also add weight to the emphasize the exclusion of any of the features. Read more about the weights of these features here.

  
function calculateRouteFromAtoB (platform) {
    var router = platform.getRoutingService(),
      routeRequestParams = {
        mode: 'fastest;truck;traffic:disabled;motorway:-2',
        representation: 'display',
        routeattributes: 'no,lg',
        RouteLegAttributeType: 'wp,mn',
        maneuverattributes: 'direction,action',
        waypoint0: '52.5274,13.38936', 
        waypoint1: '52.51118,13.45179', 
      };

    router.calculateRoute(
      routeRequestParams,
      onSuccess,
      onError
    );
  }

Try toggling the traffic mode and route features to see the changes in the routes.

Truck Type

This parameter lets you declare the type of the truck and goes further to mention the number of trailers attached to it. This feature is useful specially as the number of trailers affect the turning radius of the vehicle and not all roads are wide enough.

  
function calculateRouteFromAtoB (platform) {
    var router = platform.getRoutingService(),
      routeRequestParams = {
        mode: 'fastest;truck;traffic:disabled;',
        representation: 'display',
        routeattributes : 'no,lg',
        RouteLegAttributeType: 'wp,mn',
        maneuverattributes: 'direction,action',
        waypoint0: '49.49205,8.42784', 
        waypoint1: '49.48739,8.46245',
        truckType: 'tractorTruck',
        trailersCount: '3'
      };

    router.calculateRoute(
      routeRequestParams,
      onSuccess,
      onError
    );
  }

Truck Profile

This feature helps you further specify the truck and what it carries. The different parameters considered are:

  • shippedHazardousGoods
  • limitedWeight
  • weightPerAxle
  • height
  • width
  • length

Consider the following example where the height of the truck is 5 meters. You will see that no valid route is found between the two waypoints for trucks that high. Try entering a lower number for height and a route will be returned for the same two waypoints.

  
function calculateRouteFromAtoB (platform) {
    var router = platform.getRoutingService(), 
    routeRequestParams = {
        mode: 'fastest;truck;traffic:disabled;', 
        representation: 'display', 
        routeattributes : 'no,lg', 
        RouteLegAttributeType: 'wp,mn',
        maneuverattributes: 'direction,action',
        waypoint0: '51.0535,13.74079', 
        waypoint1: '54.07906,12.13216',
        height:'5'
    };
    router.calculateRoute(
        routeRequestParams,
        onSuccess,
        onError
      );
    }

You can also specify the content of the trucks with ' shippedHazardousGoods:explosive/flammable'. This excludes roads prohibited for shipment of explosive and flammable materials from route calculation.

After applying all parameters, you may find that no route is available between the entered waypoints. It is also possible that you have imprecise location in the first place. In such conditions to get an approximate route, you can set the truck restriction penalty to soft . Note that the soft penalty requires the route notes to be enabled in the response. You can read the violated restriction from the response and add a pop up to mention the restriction that is violated. Try the example here.

We now have an overview of the different parameters that can be set for Truck navigation which sets it apart from car navigation. Try the different parameters and its values to get an idea of the effect it has for different routes. You will thus get distinct routes for your fleet of trucks. Now that we have talked about trucks, in the next article we will tackle a different aspect of Fleet Telematics - Custom locations. Until then, keep coding!