Horizon hazards
The Hazards Warning service helps drivers anticipate potential dangers on the road. It provides safety-related warnings about upcoming hazardous situations, such as slippery surfaces, animals or objects in the roadway, reduced visibility due to fog, and other hazards.
The Hazards SDK provides data for various categories of hazards, including:
Configuring horizon
After completing the Retrieving horizon data guide, you can subscribe for horizon updates and start navigation to retrieve horizon data.
Specifying horizon options
To subscribe to hazard horizon elements, create HorizonOptions via the createHorizonOptions method and specify HazardElementType in the list of element types of interest. The horizon path parameters defined within createHorizonOptions are appropriate for most use cases and can be utilized in both free driving and active guidance scenarios.
val horizonOptions = buildHorizonOptions(listOf(HazardElementType)) When using the Extended flavor
If you prefer to configure the horizon path parameters manually, you can create the HorizonOptions as follows:
val horizonOptions = HorizonOptions( elementTypes = listOf(HazardElementType), mainPathSearchOptions = MainPathSearchOptions( searchDistancePolicy = ExplicitDistancePolicy( searchDistance = PathSearchDistance(maxHorizonLength = Distance.kilometers(2)), ), ), subPathSearchOptions = listOf( SubPathSearchOptions( searchDistance = PathSearchDistance(maxHorizonLength = Distance.meters(100)), ), ), numberOfPaths = 10, )Registering a horizon updated listener
Before starting navigation, register a HorizonUpdatedListener to listen for horizon updates with the horizon options you have defined.
tomTomNavigation.addHorizonUpdatedListener(horizonOptions, horizonUpdatedListener)Starting navigation
Then, start navigation with a route as described in the Retrieving horizon data guide.
val routePlan = RoutePlan(route, routePlanningOptions)val navigationOptions = NavigationOptions(routePlan)tomTomNavigation.start(navigationOptions)Retrieving hazards
With navigation started, you will now listen to horizon updates and retrieve hazard data.
Filtering hazards
Some of the retrieved hazards may not be relevant to the driver. For example, the driver may not be interested in strong winds as it is not a concern for the vehicle location. To filter out irrelevant hazards, you can simply add additional filtering during the retrieval of the hazard horizon elements :
private fun HorizonPath.retrieveHazardElements(): List<HazardElement> = getElements(HazardElementType) .map { it as HazardElement } .filter { element -> // Filters out hazards of type StrongWind element.hazard.type != HazardType.StrongWind }Next steps
Now that you know how to retrieve horizon hazards data, here are the recommendations on what to explore next: