Create your own provider

VERSION 1.20.1

Within the TomTom SDKs, developers are not limited to the provided location providers. They can also use their own implementations of the LocationProvider interface. This means developers can use their own services to record locations, or develop their own custom simulated location updates. Do not forget to add the specific Location module. See more information in the Quickstart.

Each predefined location provider implements the LocationProvider interface and is used in the same way. This guide shows how to use the LocationProvider. To see how to use it with the Map Display module go to Showing User Location. The engine is also used by the Navigation module to configure navigation.

  1. Initialize one of the Built-in Location Providers or your custom implementation.
  2. Set the location provider to either the map or navigation.
    tomTomMap.setLocationProvider(locationProvider)
  3. Enable the engine to receive location updates.
    locationProvider.enable()
  4. At any time the LocationProvider can be disabled to stop receiving location updates. If the engine will not be used anymore, dispose of its resources.
    locationProvider.disable()
    locationProvider.close()
  5. Location updates can be observed using OnLocationUpdateListener. Set it to the LocationProvider instance. Remember to unregister set listeners if they are no longer needed.
    1val onLocationUpdateListener =
    2 OnLocationUpdateListener { location: GeoLocation -> /* YOUR CODE GOES HERE */ }
    3locationProvider.addOnLocationUpdateListener(onLocationUpdateListener)
    4locationProvider.removeOnLocationUpdateListener(onLocationUpdateListener)
  6. The LocationProvider has a property with the last known GeoLocation. If the location was not determined yet, it will not be returned.
    val lastLocation = locationProvider.lastKnownLocation

Next steps

Since you have learned how to create your own location provider, here are recommendations for the next steps: