Create your own provider
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.
- Initialize one of the Built-in Location Providers or your custom implementation.
- Set the location provider to either the map or navigation.
tomTomMap.setLocationProvider(locationProvider)
- Enable the engine to receive location updates.
locationProvider.enable()
- 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() - Location updates can be observed using
OnLocationUpdateListener
. Set it to theLocationProvider
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) - The
LocationProvider
has a property with the last knownGeoLocation
. 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: