Traffic

VERSION 2.1.2

This guide provides instructions on how to enable or disable traffic incidents on your route, along with guidance on requesting a list of traffic incidents specific to your route. Additionally, it elaborates on the various types of traffic incidents that are supported and may be encountered during your journey.

Project setup

  1. Before proceeding, follow the Quickstart guide for Maps and the Quickstart guide for Navigation to create the TomTomMap and TomTomNavigation objects, which are essential for using the Navigation Visualization module that displays on-route traffic incidents.
  2. Add the Navigation Visualization dependency to the build.gradle file of your application module and synchronize the project:
    implementation("com.tomtom.sdk.maps.visualization:navigation:2.1.2")
  3. Use the NavigationVisualizationFactory.create method to create the NavigationVisualization object:
    navigationVisualization =
    NavigationVisualizationFactory.create(tomTomMap, tomtomNavigation)

Displaying traffic incidents on the route

To display traffic incidents on the route, call the displayRoutePlan function with a RoutePlan:

navigationVisualization.displayRoutePlan(routePlan)

By default, traffic incidents on the route are enabled. However, if you want to disable them, use trafficIncidentsEnabled. To retrieve the list of displayed TrafficIncident objects on a route, use getTrafficIncidents:

navigationVisualization.traffic.getTrafficIncidents(route)
center

Traffic incident types

We currently support four types of traffic incidents that may occur on a route:

Jam

Jam incidents denote regular traffic congestion. They are identifiable by a numeric marker indicating the delay in minutes. These delays fall into three categories:

Minor

minor

Moderate

moderate

Major

major

RoadWorks

Road works may appear in one of four magnitudes:

Unknown

unknown

Minor

minor

Moderate

moderate

Major

major

RoadClosed

Although closed roads are typically avoided during routing, users might deviate from the suggested path and enter closed roads. The RoadClosed incident type does not have an associated magnitude.

road closed

Unknown

Incidents that do not fall into the above categories are grouped under the Unknown category. These can also be classified by magnitude:

Unknown

unknown

Minor

minor

Moderate

moderate

Major

major

Traffic style customization

While creating the NavigationVisualization object using NavigationVisualizationFactory.create, you can pass in a StyleConfiguration to define custom styling. If not specified, the default style is applied. To define a custom style for traffic, use RouteTrafficIncidentStyle. Pass the custom style object like this:

1navigationVisualization =
2 NavigationVisualizationFactory.create(
3 tomTomMap,
4 tomtomNavigation,
5 styleConfiguration = StyleConfiguration(routeTrafficIncident = customTrafficStyle),
6 )

Next steps

Since you have learned how to display traffic incidents on a route, here are recommendations for the next steps: