SDK for Android Developer's Guide

Traffic Information

Traffic information can be displayed on the Map, depending on traffic data availability, by using Map.setTrafficInfoVisible(true) and setting the map to a traffic-enabled map scheme. Traffic visualization requires a network data connection to download real time traffic information. However, traffic information may continue to be displayed thereafter without a connection until the traffic events expire or the visibility is toggled.

The current traffic-enabled map schemes are:
  • Map.Scheme.HYBRID_TRAFFIC_DAY
  • Map.Scheme.HYBRID_TRAFFIC_NIGHT
  • Map.Scheme.NORMAL_TRAFFIC_DAY
  • Map.Scheme.NORMAL_TRAFFIC_NIGHT
  • Map.Scheme.CARNAV_TRAFFIC_DAY
  • Map.Scheme.CARNAV_TRAFFIC_NIGHT
  • Map.Scheme.CARNAV_TRAFFIC_HYBRID_DAY
  • Map.Scheme.CARNAV_TRAFFIC_HYBRID_NIGHT

Traffic visualization is refreshed when one of the following happens:

  1. The map is moved by a significant distance
  2. The map is not moved for 1 minute. This duration can be set using TrafficUpdater.setRefreshInterval().

Traffic Flow

The following figure shows a sample traffic visualization.

Figure 1. Traffic information with color coded lines

Traffic flow lines are color coded as follows:

Green Normal
Amber High
Red Very High
Black Blocking

Traffic Information Example on GitHub

You can find an example that demonstrates this feature at https://github.com/heremaps/.

Controlling Traffic Display

You can further control traffic display by calling Map.getMapTrafficLayer() and using the MapTrafficLayer object.

With MapTrafficLayer you can individually disable Traffic Flow, Traffic Incidents, or On-Route Traffic as well as filter traffic that is displayed according to the minimal severity level.

For example, you can set the map to only display traffic flow lines that are "very high" (red) or "blocking" (black) by performing the following:

MapTrafficLayer traffic = map.getMapTrafficLayer();
// set the minimum displayed traffic level
traffic.setDisplayFilter(TrafficEvent.Severity.VERY_HIGH);

Controlling Traffic Updates

By default traffic events are automatically loaded inside the viewport when traffic is enabled. You can also explicitly fetch traffic around a given set of geocoordinates by using TrafficUpdater.request(GeoCoordinate, int, Listener).

To completely customize the traffic-updating implementation in your app, first turn off automatic traffic updates via the TrafficUpdater.disableAutoUpdate() method, then use the above mentioned method to fetch traffic only when it is required.

Note: Since downloading and decoding traffic data can be computationally costly, do not fetch traffic for the same area too frequently. For example, if you are fetching traffic only around the user position, do not fetch more frequently than once a minute. For lower end devices fetch data in even less frequent intervals, such as once every five minutes.

Selecting Traffic Objects and Events

Traffic events are selectable through map gestures and OnGestureListener.onMapObjectsSelected(List<ViewObject>). A user selectable TrafficEventObject contains live traffic event information and is presented on the map in different forms. The following figures illustrate three examples:

Figure 2. TrafficEventObject example: Roadwork
Figure 3. TrafficEventObject example: Accident
Figure 4. TrafficEventObject example: Road Closed

To acquire information about a tapped TrafficEventObject (see MapObjects), use onMapObjectsSelected(List<ViewObject>) as in the following:


private MapGesture.OnGestureListener listener = new MapGesture.OnGestureListener() {
  ...
  @Override
  public boolean onMapObjectsSelected(List<ViewObject> objects) {
    for (ViewObject obj : objects) {
      if (obj.getBaseType() == ViewObject.Type.PROXY_OBJECT) {
        MapProxyObject proxyObj = (MapProxyObject) obj;
        if (proxyObj.getType() == MapProxyObject.Type.TRAFFIC_EVENT) {
          TrafficEventObject trafficEventObj =
                 (TrafficEventObject) proxyObj;
          TrafficEvent trafficEvent =
                  trafficEventObj.getTrafficEvent();
          Toast.makeText(getApplicationContext(), trafficEvent.getEventText(),
                  Toast.LENGTH_LONG).show();
        }
      }
    }

  return true;
};