Create your own engine
Within the TomTom SDKs, developers are not limited to the provided location engines. They can also use their own implementations of the LocationEngine
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 engine implements the LocationEngine
interface and is used in the same way. This guide shows how to use the LocationEngine
. 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 Engines or your custom implementation.
- Set the location engine to either the map or navigation.tomTomMap.setLocationEngine(locationEngine)
- Enable the engine to receive location updates.locationEngine.enable()
- At any time the
LocationEngine
can be disabled to stop receiving location updates. If the engine will not be used anymore, dispose of its resources.locationEngine.disable()locationEngine.dispose() - Location updates can be observed using
OnLocationUpdateListener
. Set it to theLocationEngine
instance. Remember to unregister set listeners if they are no longer needed.1val onLocationUpdateListener =2 OnLocationUpdateListener { location: GeoLocation -> /* YOUR CODE GOES HERE */ }3locationEngine.addOnLocationUpdateListener(onLocationUpdateListener)4locationEngine.removeOnLocationUpdateListener(onLocationUpdateListener) - The
LocationEngine
has a property with the last knownGeoLocation
. If the location was not determined yet, it will not be returned.val lastLocation = locationEngine.lastKnownLocation