Location tracking
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 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 used only by navigation, you must close its instance after updating the TomTomNavigation
object.
To access the current LocationProvider
, use:
val currentLocationProvider = tomTomNavigation.locationProvider
To change the LocationProvider
, use:
1val oldLocationProvider = tomTomNavigation.locationProvider2tomTomNavigation.locationProvider = locationProvider3oldLocationProvider.close()
Map-matched locations
Locations provided by a location service have an element of inaccuracy. Using raw locations to update the user’s current position can result in 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
. These matched locations are observed through the LocationMapMatchedListener
.
1val locationMapMatchedListener =2 LocationMapMatchedListener { mapMatchingResult: MapMatchingResult ->3 // Your code goes here4 }5tomTomNavigation.addLocationMapMatchedListener(locationMapMatchedListener)
To remove a previously added listener, call TomTomNavigation.removeLocationMapMatchedListener(LocationMapMatchedListener)
.
tomTomNavigation.removeLocationMapMatchedListener(locationMapMatchedListener)
To simplify providing a map-matched location to the TomTomMap
, the Navigation module provides the LocationProvider
. This is a specialized implementation of a LocationProvider
that integrates with TomTomNavigation
.
Before using the map-matched LocationProvider
, add the module dependency to the build.gradle.kts
file of your application module and synchronize the project:
implementation("com.tomtom.sdk.location:provider-map-matched:1.26.0")
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 may lag behind real-time conditions on the road. Using such delayed locations to update the user’s position can lead to a poor navigation experience.
Predicted locations are generated more frequently and typically offer a closer approximation of the user’s real-time position.
To reduce this lag, TomTomNavigation
generates location predictions based on incoming locations.
Location predictions are part of the MapMatchingResult
which is provided by the LocationMapMatchedListener
. See the Map-matched locations section for more information about the 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: