Location tracking

VERSION 0.13.0
PUBLIC PREVIEW

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 NavigationConfiguration object. If no LocationProvider is set during configuration, the DefaultCLLocationProvider will be 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 NavigationConfiguration.

1let configuration = NavigationConfiguration(
2 apiKey: "<NAVIGATION-KEY>",
3 locationProvider: customLocationProvider,
4 routeReplanner: routeReplanner
5)
6
7let navigation = Navigation(configuration: configuration)

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 Navigation.

To access the current LocationProvider use:

let currentLocationProvider = navigation.locationProvider

To change the LocationProvider use:

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, Navigation produces map-matched locations based on raw locations from the provided LocationProvider. Map-matched location updates are reported using NavigationMapMatchingObserver events.

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

To display locations on the map, a LocationProvider needs to be set to a TomTomMap. The calls to onLocationUpdated 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 Navigation can be set to the map. This provider calls onLocationUpdated with map-matched locations.

To set the map-matched location provider provided by Navigation 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.

Navigation generates location predictions from the provided locations. Prediction updates are reported via NavigationMapMatchingObserver events.

Next steps

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