Traffic

The Maps API provides a means of retrieving and displaying traffic data on the map for major urban areas around the globe.

Showing Traffic Flow on the Map

The example below uses the traffic component in the Maps API to show a map of a part of Berlin indicating the traffic conditions. Roads where traffic flows freely are marked in green, roads where congestion is moderate are in orange, while those that are congested are shown in red.

The API provides access to map tiles with traffic information through the HERE Traffic API. It automatically adds the flow layer to the default layer collection (accessed through the method createDefaultLayers() on the H.service.Platform instance). The application user can switch the traffic flow information display on and off for the available map types via the MapSettingsControl.

The code below adds the flow layer available in the default layer collection to the map.

map.addLayer(defaultLayers.vector.normal.traffic);
Map showing traffic flow data
Figure 1. Map showing traffic flow data

Note

By default, the traffic layer is updated every three minutes. You can change this interval by instantiating your own traffic layer and providing the desired value to the constructor.

Showing Traffic Incidents on the Map

In addition to traffic flow, the API integrates traffic incident data by providing a marker overlay that can be added to the map.

The code below adds the pre-configured traffic incidents marker layer available in the default layer collection to the map to show traffic incidents.

map.addLayer(defaultLayers.vector.normal.trafficincidents);

This code assumes that map is a previously instantiated and initialized instance of H.Map.

The MapSettingsControl includes an entry for switching traffic incidents display on and off if the traffic incident layer is detected in the collection of layers passed to the UI.

Map showing traffic data
Figure 2. Map showing traffic data

Note

By default, the traffic layer is updated every three minutes. You can change this interval by instantiating your own traffic layer and providing the desired value to the constructor.

results matching ""

    No results matching ""