Additional traffic features
- Last UpdatedMay 2, 2025
- 4 minute read
Enhance your map applications with real-time traffic data using HERE SDK's advanced traffic features. Display live traffic flow and incidents on the map to keep users informed and help them navigate efficiently. Additionally, you can pick and highlight specific traffic incidents for a detailed view.
Show real-time traffic flow and incidents on the map
You can easily visualize traffic incidents on the map by enabling the map layer state trafficIncidents
. The HERE SDK also supports a separate layer to see the current traffic situation. See the example below for how to show or hide a layer on the map.
After a layer is set, the visible area of the map is automatically updated. So you can freely pan the map in all directions to see the latest traffic incidents.
In many situations, drivers are interested in finding the fastest route based on the current traffic jams in a city - or outside a city. The HERE SDK allows you to show a layer holding all the current traffic jams, visualized by lines in different colors to indicate the severity of the jam - always updated in real-time. This feature requires an online connection and consumes slightly more data. However, the traffic lines are shown as part of the map tiles and are therefore highly performant.
Together - or independently - you can visualize such traffic information on the map with just a few lines of code:
Optionally, for MapFeatures.trafficFlow
and MapFeatures.trafficIncidents
you can also specify how often a request should be initiated in order to fetch the latest traffic data from the backend. This is most useful in a scenario where the map view remains static. Regardless of the traffic refresh period setting, when a viewport change occurs, the HERE SDK may need to fetch new traffic data to render the updated viewport correctly.
Setting a new layer state is performed synchronously, but it requires a valid map scene that must have been loaded before. Also, setting a new layer state while a new map scene is being loaded, may result in an exception. For hiding feature layers, you can call:
The traffic flow lines are color coded as follows:
- Green: Normal traffic
- Amber/Yellow: High traffic
- Red: Very high traffic
- Black: Blocking traffic
A usage example is available on GitHub as part of the "traffic_app" example app.
Pick traffic incidents
When the trafficIncidents
is shown on the MapView
, you can set up a tap handler and pick the traffic incidents to get more information.
With the tap handler, we get the touched location in view coordinates that can be passed to mapView.pickMapContent()
. Here, we just use a point-sized rectangle, but you can also enlarge the pick area to include more content at once.
The callback provides a PickMapContentResult
which can contain a TrafficIncidentResult
, but also other embedded types like default POI markers, that are always visible on the map. The TrafficIncidentResult
type already provides most information about the incident, but to get all available information, we can use the TrafficEngine
(see also below) to search for the picked incident by ID: