Traffic
The Navigation SDK for iOS is only available upon request. Contact us to get started.
This guide will provide you with 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, we will elaborate on the various types of traffic incidents that are supported and may be encountered during your journey.
Project setup
- Before proceeding with this guide, follow the Quickstart guide for Maps and Quickstart guide for Navigation to create the
TomTomMap
andTomTomNavigation
objects, which are essential for use with the Navigation Visualization module responsible for displaying on-route traffic incidents. - The Navigation Visualization for iOS can be integrated into your project with Swift Package Manager (SPM). Follow the guide in Project setup for navigation to add tomtom-sdk-spm-navigation package.
- Use the
NavigationVisualizationFactory.create(map:navigation:styleConfiguration:)
method to create theNavigationVisualization
object:
navigationVisualization = NavigationVisualizationFactory.create(map: map, navigation: navigation)
Displaying traffic incidents on the route
To display traffic incidents on the route, call the NavigationVisualization.displayRoutePlan(_:)
function with a RoutePlan
:
navigationVisualization.displayRoutePlan(routePlan)
By default, traffic incidents on the route are enabled. However, if you want to disable them, you can do so by using NavigationVisualization.areTrafficIncidentsEnabled
. To retrieve the list of displayed TrafficIncident
s on a Route
, use NavigationVisualization.trafficIncidents(on:)
like this:
navigationVisualization.trafficIncidents(on: route)
![traffic on route](https://developer.tomtom.com/assets/downloads/tomtom-sdks/android/maps/traffic/traffic_on_route.png)
Traffic incident types
We currently offer support for four types of traffic incidents on the route, which include:
Jam incidents denote regular traffic congestion, identifiable by a numeric marker that represents delays in minutes. These delays can fall into three categories:
Minor
![minor](https://developer.tomtom.com/assets/downloads/tomtom-sdks/android/maps/traffic/jam/minor.png)
Moderate
![moderate](https://developer.tomtom.com/assets/downloads/tomtom-sdks/android/maps/traffic/jam/moderate.png)
Major
![major](https://developer.tomtom.com/assets/downloads/tomtom-sdks/android/maps/traffic/jam/major.png)
TrafficIncidentCategory.roadWorks
Road works can come in four different magnitudes:
Unknown
![unknown](https://developer.tomtom.com/assets/downloads/tomtom-sdks/android/maps/traffic/roadworks/unknown.png)
Minor
![minor](https://developer.tomtom.com/assets/downloads/tomtom-sdks/android/maps/traffic/roadworks/minor.png)
Moderate
![moderate](https://developer.tomtom.com/assets/downloads/tomtom-sdks/android/maps/traffic/roadworks/moderate.png)
Major
![major](https://developer.tomtom.com/assets/downloads/tomtom-sdks/android/maps/traffic/roadworks/major.png)
TrafficIncidentCategory.roadClosed
While we typically avoid routing through closed roads, there might be situations where users deviate from the original route to a closed road. The RoadClosed incident has no associated magnitude, unlike other incident types.
![road closed](https://developer.tomtom.com/assets/downloads/tomtom-sdks/android/maps/traffic/roadclosed/road-closed.png)
TrafficIncidentCategory.unknown
Incidents that do not fall into the categories mentioned earlier are represented under the "unknown" category. Similar to road works, they can also be categorised into four different magnitudes:
Unknown
![unknown](https://developer.tomtom.com/assets/downloads/tomtom-sdks/android/maps/traffic/unknown/unknown.png)
Minor
![minor](https://developer.tomtom.com/assets/downloads/tomtom-sdks/android/maps/traffic/unknown/minor.png)
Moderate
![moderate](https://developer.tomtom.com/assets/downloads/tomtom-sdks/android/maps/traffic/unknown/moderate.png)
Major
![major](https://developer.tomtom.com/assets/downloads/tomtom-sdks/android/maps/traffic/unknown/major.png)
Traffic style customisation
During the creation of NavigationVisualization
through the NavigationVisualizationFactory.create(map:navigation:styleConfiguration:)
, StyleConfiguration
can be passed in to define custom stylization. By default, if it’s not passed in, the default style will be used. To define a custom stylization for traffic, see RouteTrafficIncidentStyle
. The custom style object can be passed as:
1navigationVisualization = NavigationVisualizationFactory.create(2 map: map,3 navigation: navigation,4 styleConfiguration: StyleConfiguration(routeTrafficIncident: customStyle)5)
Next steps
Since you have learned how to display traffic incidents on the route, here are recommendations for the next steps: