Location tracking

VERSION 0.49.0

The Navigation SDK for iOS is only available upon request. Contact us to get started.

A good navigation experience requires reliable and frequent location updates.

Providing a location provider

You must select a source of location updates for your navigation. To do this, you can use the LocationProvider protocol. If you want to learn more about this protocol, consult the Location quickstart guide. The LocationProvider used for navigation is initially specified using the OnlineTomTomNavigationFactory.Configuration object. If no LocationProvider is set during configuration, the DefaultCLLocationProvider is used by navigation. You can read more about existing location providers in Built-in location providers.

To set a custom LocationProvider during navigation configuration use OnlineTomTomNavigationFactory.Configuration.

1let navigationConfiguration = OnlineTomTomNavigationFactory.Configuration(
2 navigationTileStore: try NavigationTileStore(config: NavigationTileStoreConfiguration(apiKey: "YOUR_TOMTOM_API_KEY")),
3 locationProvider: customLocationProvider,
4 routePlanner: routePlanner
7let navigation = try OnlineTomTomNavigationFactory.create(configuration: navigationConfiguration)

You can retrieve and change the provider responsible for location updates at any time. This can be done by accessing the location provider property of TomTomNavigation.

To access the current LocationProvider use:

let currentLocationProvider = navigation.locationProvider

To change the LocationProvider use:

var navigation = navigation
navigation.locationProvider = locationProvider

Map-matched locations displayed on the map

Locations provided by a location service have an element of inaccuracy. Using the raw location to update the user’s current position on the map can lead to a position indicator that is not aligned with the Route or the road network. To solve this problem, TomTomNavigation produces map-matched locations based on raw locations from the provided LocationProvider. Map-matched location updates are reported using LocationMapMatchingObserver events.

1func didMapMatchLocation(mapMatchingResult: MapMatchingResult) {
2 /* Your code goes here */

To display locations on the map, a LocationProvider needs to be set to a TomTomMap. The calls to LocationProviderObservable.onLocationUpdated(location:) on the location engine are reflected on the map. To assure that the location on the map is map-matched, the map-matched location provider provided by TomTomNavigation can be set to the map. This provider calls LocationProviderObservable.onLocationUpdated(location:) with map-matched locations.

To set the map-matched location provider (provided by TomTomNavigation) to the map, use:

let mapMatchedLocationProvider = navigation.mapMatchedLocationProvider
map.locationProvider = mapMatchedLocationProvider

Predicted locations

Location updates from location services can lag behind the current situation on the road. Updating the current position with such locations leads to a bad user experience during navigation. Locations that come from predictions are generated more often and can provide a closer approximation of the user’s location.

TomTomNavigation generates location predictions from the provided locations. Prediction updates are reported via LocationMapMatchingObserver events.

Next steps

Since you have learned about location tracking, here are recommendations for the next steps: