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
protocol. 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
protocol 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 Map User Location. The provider is also used by the Navigation module to configure navigation.
-
Initialize one of the Built-in Location Providers or your own custom implementation.
-
Set the location provider to either the map or navigation.
1let customLocationProvider = DefaultCLLocationProvider()2let configuration = NavigationConfiguration(3 apiKey: "<NAVIGATION-KEY>",4 locationProvider: customLocationProvider,5 routeReplanner: routeReplanner6)7let navigation = Navigation(configuration: configuration) -
Enable the provider to receive location updates.
locationProvider.start() -
At any time the
LocationProvider
can be disabled to stop receiving location updates.locationProvider.stop() -
Location updates can be observed using the
LocationProviderObservable
protocol.1func onLocationUpdated(location: GeoLocation) {2 /* YOUR CODE GOES HERE */3}45func onHeadingUpdate(newHeading: CLHeading, lastLocation: GeoLocation) {6 /* YOUR CODE GOES HERE */7}89func onAuthorizationStatusChanged(isGranted: Bool) {10 /* YOUR CODE GOES HERE */11}Extend your class with this protocol and add it to the
LocationProvider
instance observers. Remember to remove the observer if it is no longer needed.locationProvider.addObserver(self)locationProvider.removeObserver(self) -
LocationProvider
has a property with the last knownGeoLocation
.let lastLocation = locationProvider.location