Location tracking

VERSION 0.3.34
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 can be found here Location module quickstart

Providing a location engine

The LocationEngine 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 LocationEngine use:

val currentLocationEngine = tomTomNavigation.locationEngine()

To change the LocationEngine use:

tomTomNavigation.setLocationEngine(locationEngine)

Map matched locations

Locations provided by a location service have a degree of inaccuracy. Using the raw location to update the current user’s position can lead to a position indicator that is not aligned with the Route. To solve this problem, TomTomNavigation produces map-matched locations based on raw locations from the provided LocationEngine. Matched locations can be observed through 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 ease up the process of providing a map-matched location into the TomTomMap, the Navigation module provides MapMatchedLocationEngine. It is a special implementation of a LocationEngine which accepts TomTomNavigation.

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

1dependencies {
2 implementation "com.tomtom.sdk:location-mapmatched:0.3.34"
3}

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

val locationEngine = MapMatchedLocationEngine(navigation = tomTomNavigation)
tomTomMap.setLocationEngine(locationEngine)

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.

To reduce the impact, TomTomNavigation generates location predictions from the provided locations. Location predictions can be observed in OnLocationPredictionGeneratedListener. The LocationPrediction object consists of a list of future positions.

1val onLocationPredictionGeneratedListener = object : OnLocationPredictionGeneratedListener {
2 override fun onLocationPredictionGenerated(prediction: LocationPrediction) {
3 /* Your code goes here */
4 }
5}
6tomTomNavigation.addOnLocationPredictionGeneratedListener(onLocationPredictionGeneratedListener)

To remove a previously-added listener, call TomTomNavigation.removeOnLocationPredictionGeneratedListener(OnLocationPredictionGeneratedListener).

tomTomNavigation.removeOnLocationPredictionGeneratedListener(onLocationPredictionGeneratedListener)

Location predictions can also be observed using MapMatchedLocationEngine.

Predictions are enabled by default in MapMatchedLocationEngine.

To turn them off use:

1val locationEngine = MapMatchedLocationEngine(
2 navigation = tomTomNavigation,
3 usePredictions = false
4)