Hazards

Hazard visualization is a sub-feature of HorizonVisualization that renders upcoming road hazards as map markers during active navigation or free driving. Hazards include accidents, broken-down vehicles, and objects on the road, among others.

Project setup

Please note that to use this guide you need to obtain an API key to get access to TomTom Maps and Navigation SDK. To obtain an API key follow these instructions. Remember to keep your API key secure.

Complete the Horizon visualization project setup to add the Navigation Visualization Compose dependency and create the TomTomNavigation, NavigationVisualization, and HorizonVisualization objects.

Hazard rendering is part of HorizonVisualization and is enabled by default. No additional configuration is required: when you initialize the TomTomSdk as shown in the Quickstart guide for Navigation, the SDK uses your API key to retrieve hazard data automatically.

hazard markers shown along the route during navigation

The visualization module configures the Horizon internally, so no manual HorizonOptions setup is needed to display hazards. If you consume hazard data yourself through the TomTomNavigation horizon listener, you must request the hazard element type explicitly in your own HorizonOptions.

Enabling and disabling hazards

To enable and disable the hazard rendering at runtime, mutate the enabled property of the hazardVisualizationState through the HorizonVisualizationState. The HorizonVisualization composable reacts to the change and updates the map accordingly.

val horizonVisualizationState = rememberHorizonVisualizationState()
// Disable hazard rendering. Hazards are enabled by default.
horizonVisualizationState.hazardVisualizationState.enabled = false

Supported hazard types

The Horizon delivers many hazard types, but the visualization renders only the most safety-critical ones. This set is fixed and is not configurable. The following types are rendered:

TypeDescriptionIcon

Accident

Road accident.


accident icon

BrokenDownVehicle

Disabled vehicle on the road.


broken-down vehicle icon

ObjectsOnRoad

Objects, debris, or animals on the road.


objects on road icon

BadRoadConditions

General road surface degradation, such as potholes.


bad road conditions icon

WrongWayDriver

Vehicle driving against the flow of traffic.


wrong-way driver icon

Other hazard types delivered by the Horizon — such as JamTailWarning, Generic, SlipperyRoad, ReducedVisibility, and StrongWind — are not rendered.

Marker placement

Each hazard marker is placed at the first geometry point of the hazard element.

Hazard markers are always placed on the left side of the route tube, while traffic incidents are placed on the right side. This way, a hazard and a traffic jam at the same location can both be shown at the same time.

hazard marker on the left side of the route tube, with a traffic incident on the right

Next steps

Now that you can display hazards, here are the recommendations on what to explore next:

Horizon visualization

Learn more about Horizon visualization and its sub-features.

Go to page

Safety locations

Display speed cameras, danger zones, and other safety locations along the route.

Go to page

Free driving

Track the driver’s location and surroundings without an active route.

Go to page