Location context

VERSION 0.44.1
PUBLIC PREVIEW

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)
4
5 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.speed
3 let speedLimit: TomTomSDKCommon.SpeedLimit? = locationContext.speedLimit
4
5 let countryCode: String? = locationContext.address?.countryCodeISO3
6 let city: String? = locationContext.address?.municipality
7 let streetName: String? = locationContext.address?.streetName
8
9 let functionalRoadClass: Int? = locationContext.road?.functionalRoadClass
10 let isRoadUnderpass: Bool? = locationContext.road?.isUnderpass
11 let isRoadTunnel: Bool? = locationContext.road?.isTunnel
12 let tunnelName: String? = locationContext.road?.tunnelName
13 let isRoadBridge: Bool? = locationContext.road?.isBridge
14 let bridgeName: String? = locationContext.road?.bridgeName
15}

Next steps

Now that you know how to retrieve location context information, here are the recommendations on what to explore next: