HERE Android SDK Developer's Guide

Traffic-Aware Navigation

With the HERE SDK, developers can enable turn-by-turn route navigation that takes live traffic information into account. NavigationManager.setTrafficAvoidanceMode() can be used to set the way in which traffic should be handled during navigation.

Three modes are available for traffic avoidance, and they are defined by the following NavigationManager.TrafficAvoidanceMode enumerations. The default mode is DISABLE.
  • DYNAMIC - Performs traffic-aware rerouting without user input.

    In this mode, the guidance engine performs periodic route calculations while the device is online. A route calculation is a server request where the server finds the most optimal route by avoiding traffic congestions and calculating speed limits. If the calculated route is different from the current route, the navigation manager automatically switches to the new route. It also triggers the NavigationManager.NavigationManagerEventListener.onRouteUpdated(Route) callback method.

    Note: You can set the frequency of the route request by using NavigationManager.setRouteRequestInterval().
  • MANUAL - Provides notifications about upcoming traffic incidents and requires user confirmation before rerouting. For more information, see the next section.
  • DISABLE - Disables traffic-based rerouting.

Manual Traffic-Based Rerouting

If the device is online and NavigationManager.TrafficAvoidanceMode.MANUAL is selected, the guidance engine considers all incoming traffic event within proximity and checks if the event is on the current route route, and whether the route is reroutable. If these conditions are true, the engine triggers a route calculation. You can listen to this recalculation event by implementing the onTrafficRerouteBegin(TrafficNotification) method in TrafficRerouteListener.

Route recalculation is a server request where the server finds the most optimal route by avoiding live traffic congestions and calculating road speed limits. If the calculated route is different from the current route, the new route is returned through the NavigationManager.TrafficRerouteListener.onTrafficRerouted(Route) callback method. A voice note is also played by the guidance engine. You can then set the new Route to the NavigationManager manually.

The TrafficWarner Class

The TrafficWarner class is responsible for enabling and handling traffic notifications. Traffic notifications occur if there is a traffic event on the current route and the user's current position is near the event.

To retrieve an instance of the TrafficWarner object, call NavigationManager.getTrafficWarner(). You then can call TrafficWarner.init() to initialize and start the TrafficWarner.

One or more of the following methods can be used to operate traffic warner, or to retrieve further information about traffic notifications:

  • isAhead(TrafficNotification) - determines whether or not a traffic notification is ahead of the last callback position
  • isOnRoute(Route, TrafficNotification) - determines if a traffic notification is on a given route
  • isValid() - determines if the traffic warner is valid
  • setAskAvoidOutput(TrafficNotification) - sets the output of the traffic notification to "Do you want to avoid.. ?"
  • setInformAvoidOutput(TrafficNotification) - sets the output of the traffic notication to "You are rerouted because of..."
  • stop() - stops the traffic warner
  • start() - starts the traffic warner

To listen for traffic notifications, a listener must be added via TrafficWarner.addListener().

The TrafficNotification and TrafficNotificationInfo Classes

TrafficWarner.Listener provides a callback that returns a TrafficNotification object that is relevant to the current navigation session. This TrafficNotification contains a list of TrafficNotificationInfo instances associated with the traffic notification, retrievable through TrafficNotification.getInfoList().

The TrafficNotificationInfo class encapsulates the details of a traffic notification. TrafficNotificationInfo.Type defines the type of traffic notification with regards to the current route.

The following methods can be used to retrieve details about a TrafficNotificationInfo instance:

  • getType() - gets the type of traffic notification info
  • getEvent() - gets the traffic event (TrafficEvent) associated with the traffic notification info
  • getDistanceInMeters() - gets the distance from the last callback position to the traffic notification