Location context
Navigation SDK for iOS is only available upon request. Contact us to get started.
While navigating, you can retrieve detailed information about the current location on the road using LocationContext
.
The SDK provides location context data such as:
- The current speed
- The speed limit
- The properties of the road (for example, the number of lanes, the functional road class and the driving side)
- The address (for example, the name of the city, the name of the street and the number on the street).
Refer to the LocationContext
API reference for more details.
This guide explains to you how to use LocationContext
to retrieve the name of the city and the name of the street at the current location.
Starting navigation
Before retrieving location context information, you need to start navigation with a route as described in the Starting navigation guide.
But, instead of adding a listener for route progress updates, make sure you add a NavigationLocationContextObserver
to listen to location context updates.
1func startNavigation() throws {2 let tomTomNavigation = try OnlineTomTomNavigationFactory.create(configuration: navigationConfiguration)3 tomTomNavigation.addLocationContextObserver(self)45 let routePlan = RoutePlan(route: route, routePlanningOptions: routePlanningOptions)6 let navigationOptions = NavigationOptions(activeRoutePlan: routePlan)7 try tomTomNavigation.start(navigationOptions: navigationOptions)8}
Retrieving location context information
With navigation started, you can listen to location context updates and retrieve the name of the city and the name of the street at the current location.
1func didDetectLocationContext(locationContext: LocationContext) {2 let speed: Measurement<UnitSpeed> = locationContext.speed3 let speedLimit: TomTomSDKCommon.SpeedLimit? = locationContext.speedLimit45 let countryCode: String? = locationContext.address?.countryCodeISO36 let city: String? = locationContext.address?.municipality7 let streetName: String? = locationContext.address?.streetName89 let functionalRoadClass: Int? = locationContext.road?.functionalRoadClass10 let isRoadUnderpass: Bool? = locationContext.road?.isUnderpass11 let isRoadTunnel: Bool? = locationContext.road?.isTunnel12 let tunnelName: String? = locationContext.road?.tunnelName13 let isRoadBridge: Bool? = locationContext.road?.isBridge14 let bridgeName: String? = locationContext.road?.bridgeName15}
Next steps
Now that you know how to retrieve location context information, here are the recommendations on what to explore next: