How to enable and disable Traffic Visualization using HERE SDK?
What is Traffic Visualization?
It is to display live traffic flow and incidents on the map to keep users informed and help them navigate efficiently.
How to enable and disable Traffic Visualization using HERE SDK?
To enabling Traffic Visualization: We call the enableTrafficVisualization method to display real-time traffic information on the map.<br />private void enableTrafficVisualization() { // Try to refresh the TRAFFIC_FLOW vector tiles 5 minutes. // If MapFeatures.TRAFFIC_FLOW 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(Duration.ofMinutes(5)); } catch (MapContentSettings.TrafficRefreshPeriodException e) { throw new RuntimeException("TrafficRefreshPeriodException: " + e.error.name()); } Map mapFeatures = new HashMap<>(); // Once these traffic layers are added to the map, they will be automatically updated while panning the map. mapFeatures.put(MapFeatures.TRAFFIC_FLOW, MapFeatureModes.TRAFFIC_FLOW_WITH_FREE_FLOW); // MapFeatures.TRAFFIC_INCIDENTS renders traffic icons and lines to indicate the location of incidents. mapFeatures.put(MapFeatures.TRAFFIC_INCIDENTS, MapFeatureModes.DEFAULT); mapView.getMapScene().enableFeatures(mapFeatures);}<br />
For disabling Traffic Visualization: Similarly, we have a method to disableTrafficVisualization and it remove traffic flow and incidents from the map.<br /> private void disableTrafficVisualization() { List mapFeatures = new ArrayList<>(); mapFeatures.add(MapFeatures.TRAFFIC_FLOW); mapFeatures.add(MapFeatures.TRAFFIC_INCIDENTS); mapView.getMapScene().disableFeatures(mapFeatures); // This clears only the custom visualization for incidents found with the TrafficEngine. clearTrafficIncidentsMapPolylines(); }<br />