Additional traffic features
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.
For the Navigate, you can also incorporate traffic information from radio stations.
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.

Screenshot: Traffic incidents visualized 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:
func enableTrafficVisualization() {
do {
// Set the traffic flow refresh period to 5 * 60 seconds (5 minutes).
// If MapFeatures.trafficFlow is disabled, no requests are made.
//
// Note: This code initiates periodic calls to the HERE Traffic backend. Depending on your contract,
// each call may be charged separately. It is the application's responsibility to decide how
// often this code should be executed.
try MapContentSettings.setTrafficRefreshPeriod(5 * 60.0)
} catch let error as MapContentSettings.TrafficRefreshPeriodError {
print("TrafficRefreshPeriodError: \(error)")
} catch {
print("An unexpected error occurred: \(error)")
}
// Once these layers are added to the map, they will be automatically updated while panning the map.
mapView.mapScene.enableFeatures([MapFeatures.trafficFlow : MapFeatureModes.trafficFlowWithFreeFlow])
// MapFeatures.trafficIncidents renders traffic icons and lines to indicate the location of incidents.
mapView.mapScene.enableFeatures([MapFeatures.trafficIncidents: MapFeatureModes.defaultMode])
}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. Setting this via MapContentSettings.setTrafficRefreshPeriod(5 * 60.0) 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.
NoteDuring turn-by-turn navigation, viewport changes can happen multiple times per second and may result in a high number of Traffic Vector Tile requests when these features are enabled. As an alternative, consider using TrafficOnRoute to update only the traffic visualization along the route itself.
For disabling the traffic layers, you can call:
mapView.mapScene.disableFeatures([MapFeatures.trafficFlow, MapFeatures.trafficIncidents])The traffic flow lines are color coded as follows:
- Green: Normal traffic
- Amber/Yellow: High traffic
- Red: Very high traffic
- Black: Blocking traffic

Screenshot: Traffic flow visualized on the map together with incidents.
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.
// Conforming to TapDelegate protocol.
func onTap(origin: Point2D) {
// Can be nil when the map was tilted and the sky was tapped.
if let touchGeoCoords = mapView.viewToGeoCoordinates(viewCoordinates: origin) {
tappedGeoCoordinates = touchGeoCoords
// Pick incidents that are shown in trafficIncidents.
pickTrafficIncident(touchPointInPixels: origin)
}
}
// Traffic incidents can only be picked, when trafficIncidents is visible.
func pickTrafficIncident(touchPointInPixels: Point2D) {
let originInPixels = Point2D(x: touchPointInPixels.x, y: touchPointInPixels.y)
let sizeInPixels = Size2D(width: 1, height: 1)
let rectangle = Rectangle2D(origin: originInPixels, size: sizeInPixels)
mapView.pickMapContent(inside: rectangle, completion: onPickMapContent)
}
// MapViewBase.PickMapContentHandler to receive picked map content.
func onPickMapContent(mapContentResult: PickMapContentResult?) {
if mapContentResult == nil {
// An error occurred while performing the pick operation.
return
}
let trafficIncidents = mapContentResult!.trafficIncidents
if trafficIncidents.count == 0 {
print("No traffic incident found at picked location")
} else {
print("Picked at least one incident.")
let firstIncident = trafficIncidents.first!
showDialog(title: "Traffic incident picked:", message: "Type: \(firstIncident.type.rawValue)")
// Find more details by looking up the ID via TrafficEngine.
findIncidentByID(firstIncident.originalId)
}
// Optionally, look for more map content like embedded POIs.
}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:
func findIncidentByID(_ originalId: String) {
let trafficIncidentsLookupOptions = TrafficIncidentLookupOptions()
// Optionally, specify a language:
// the language of the country where the incident occurs is used.
// trafficIncidentsLookupOptions.languageCode = LanguageCode.EN_US
trafficEngine.lookupIncident(with: originalId,
lookupOptions: trafficIncidentsLookupOptions,
completion: onTrafficIncidentCompletion)
}
// TrafficIncidentCompletionHandler to receive traffic incidents from ID.
func onTrafficIncidentCompletion(trafficQueryError: TrafficQueryError?, trafficIncident: TrafficIncident?) {
if trafficQueryError == nil {
print("Fetched TrafficIncident from lookup request." +
" Description: " + trafficIncident!.description.text)
} else {
showDialog(title: "TrafficLookupError:", message: trafficQueryError.debugDescription)
}
}A usage example is available on GitHub as part of the "Traffic" example app.
Get traffic broadcasts from radio stations (only available for Navigate)
With the TrafficDataProvider interface the HERE SDK allows to integrate radio station signals providing traffic broadcasts.
A TrafficBroadcast expects traffic data in the RDS-TMC format and can be used without an internet connection. In such cases, the OfflineRoutingEngine can utilize traffic data received over the radio channel, provided the rdsTraffic layer is enabled using LayerConfiguration. For more information on how to use LayerConfiguration, see here.
The trafficBroadcast.activate() method needs to be called to receive traffic data events.
A TrafficBroadcast continuously reacts to new locations provided from a location source and acts as a LocationListener. The location must be updated regardless of calling activate().
Note (only applicable for Navigate)In order to adopt the interface special hardware is required. Talk to your HERE representative for more details. Note that this feature is released as a beta feature.
Updated 10 hours ago