Location tracking

VERSION 0.3.1106
PUBLIC PREVIEW

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 NavigationConfiguration object. However, you can retrieve and change the engine responsible for location updates at any time.

To access the current LocationProvider use:

val currentLocationProvider = tomTomNavigation.locationProvider

To change the LocationProvider use:

tomTomNavigation.locationProvider = locationProvider

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 problem, TomTomNavigation produces map-matched locations based on raw locations from the provided LocationProvider. Matched locations are observed through the OnLocationMatchedListener.

1val onLocationMatchedListener = object : OnLocationMatchedListener {
2 override fun onLocationMatched(location: GeoLocation) {
3 /* Your code goes here */
4 }
5}
6tomTomNavigation.addOnLocationMatchedListener(onLocationMatchedListener)

To remove a previously-added listener, call TomTomNavigation.removeOnLocationMatchedListener(OnLocationMatchedListener).

tomTomNavigation.removeOnLocationMatchedListener(onLocationMatchedListener)

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

Before using the MapMatchedLocationProvider, add the module dependency in the build.gradle of your application module and synchronize the project:

1dependencies {
2 implementation "com.tomtom.sdk.location:provider-map-matched:0.3.1106"
3}

Then you can create MapMatchedLocationProvider and use it in the TomTomMap.

val locationProvider = MapMatchedLocationProvider(navigation = tomTomNavigation)
tomTomMap.setLocationProvider(locationProvider)

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 the impact, TomTomNavigation generates location predictions from the provided locations. Location predictions are observed in OnLocationPredictionsGeneratedListener.

1val onLocationPredictionsGeneratedListener = object : OnLocationPredictionsGeneratedListener {
2 override fun onLocationPredictionsGenerated(predictions: List<GeoLocation>) {
3 /* Your code goes here */
4 }
5}
6tomTomNavigation.addOnLocationPredictionsGeneratedListener(onLocationPredictionsGeneratedListener)

To remove a previously-added listener, call TomTomNavigation.removeOnLocationPredictionsGeneratedListener(OnLocationPredictionsGeneratedListener).

tomTomNavigation.removeOnLocationPredictionsGeneratedListener(onLocationPredictionsGeneratedListener)

Location predictions can also be observed using MapMatchedLocationProvider.

Predictions are enabled by default in MapMatchedLocationProvider.

To turn off predictions use:

1val locationProvider = MapMatchedLocationProvider(
2 navigation = tomTomNavigation,
3 usePredictions = false
4)

Next steps

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