You can 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 with
trafficFlow. See the example below for how to show or hide such layers 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:
_hereMapController.mapScene.setLayerState(MapSceneLayers.trafficFlow, MapSceneLayerState.visible); _hereMapController.mapScene.setLayerState(MapSceneLayers.trafficIncidents, MapSceneLayerState.visible);
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 a layer, you can call the above with
MapSceneLayerState.hidden instead of
The traffic flow lines are color coded as follows:
In addition, you can also indicate the traffic along a
Route instance as shown in the Directions section.
A usage example is available on GitHub as part of the traffic_app example app.