Location tracking

VERSION 1.20.1

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

A good navigation experience requires reliable and frequent location updates.

More details about the TomTom Location module are in the: Location module quickstart document.

Providing a location provider

The LocationProvider used for navigation is initially specified using the Configuration object. However, you can retrieve and change the LocationProvider responsible for location updates at any time.

If the LocationProvider is only used by the navigation, you have to close its instance after updating the TomTomNavigation.

To access the current LocationProvider use:

val currentLocationProvider = tomTomNavigation.locationProvider

To change the LocationProvider use:

1val oldLocationProvider = tomTomNavigation.locationProvider
2tomTomNavigation.locationProvider = locationProvider
3oldLocationProvider.close()

Map-matched locations

Locations provided by a location service have an element of inaccuracy. Using the raw location to update the current user’s position can lead to a position indicator that is unaligned with the Route. To solve this inaccuracy problem, TomTomNavigation produces map-matched locations based on raw locations from the provided LocationProvider. Matched locations are observed through the LocationMapMatchedListener.

1val locationMapMatchedListener =
2 LocationMapMatchedListener { mapMatchingResult: MapMatchingResult ->
3 // Your code goes here
4 }
5tomTomNavigation.addLocationMapMatchedListener(locationMapMatchedListener)

To remove a previously-added listener, call TomTomNavigation.removeLocationMapMatchedListener(LocationMapMatchedListener).

tomTomNavigation.removeLocationMapMatchedListener(locationMapMatchedListener)

To make it easier to provide a map-matched location into the TomTomMap, the Navigation module provides the map-matched LocationProvider. It is a special implementation of a LocationProvider that accepts TomTomNavigation.

Before using the map-matched LocationProvider, add the module dependency in the build.gradle.kts of your application module and synchronize the project:

implementation("com.tomtom.sdk.location:provider-map-matched:1.20.1")

Then you can create a map-matched LocationProvider and use it in the TomTomMap.

val mapMatchedLocationProvider = MapMatchedLocationProviderFactory.create(navigation = tomTomNavigation)
tomTomMap.setLocationProvider(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 frequently and often provide a closer approximation of the user’s location.

To reduce this lag effect, TomTomNavigation generates location predictions from the provided locations.

Location predictions are part of the MapMatchingResult provided by the LocationMapMatchedListener. See Map-matched locations section for more information on LocationMapMatchedListener.

Location predictions can also be observed using a map-matched LocationProvider.

Predictions are enabled by default in a map-matched LocationProvider.

To turn off predictions use:

1val mapMatchedLocationProviderWithoutPrediction = MapMatchedLocationProviderFactory.create(
2 navigation = tomTomNavigation,
3 usePredictions = false,
4)

Next steps

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