Location tracking

VERSION 0.2.1455
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 engine

A source of location updates needs to be set to navigation. For this purpose the LocationEngine protocol can be used. Read more about this protocol in the Location quickstart guide. The LocationEngine used for navigation is initially specified using the NavigationConfiguration object. If no LocationEngine is set during configuration, the DefaultCLLocationEngine will be used by navigation. Read more about existing location engines in the Built-in location engines.

To set a custom LocationEngine during navigation configuration use NavigationConfigurationBuilder.

1let configuration = NavigationConfigurationBuilder(
2 navigationKey: "<NAVIGATION-KEY>",
3 locationEngine: customLocationEngine,
4 routingService: routingService
5)
6.build()
7let navigation = Navigation(configuration: configuration)

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

To access the current LocationEngine use:

let currentLocationEngine = navigation.locationEngine

To change the LocationEngine use:

navigation.locationEngine = locationEngine

Map-matched locations displayed on the map

Locations provided by a location service have a degree 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 LocationEngine. Map-matched location updates will be reported via TomTomNavigationDelegate events.

1func tomTomNavigation(_: Navigation, didMapMatchLocation _: GeoLocation) {
2 /* Your code goes here */
3}

To display locations on the map, a LocationEngine needs to be set to TomTomMap. The calls to onLocationUpdated on the location engine will be reflected on the map. To achieve that the location on the map is map-matched, the map-matched location engine provided by Navigation can be set to the map. This engine will call onLocationUpdated with map-matched locations.

To set the map-matched location engine provided by Navigation to the map use:

let mapMatchedLocationEngine = navigation.mapMatchedLocationEngine
map.setCustomLocationEngine(mapMatchedLocationEngine)

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 will be reported via TomTomNavigationDelegate events.

1func tomTomNavigation(_: Navigation, nextPredictionGenerated _: [GeoLocation]) {
2 /* Your code goes here */
3}