Create your own provider

VERSION 0.45.0
PUBLIC PREVIEW

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.

  1. Initialize one of the Built-in Location Providers or your own custom implementation.

  2. Set the location provider to either the map or navigation.

    1let customLocationProvider = DefaultCLLocationProvider()
    2let configuration = OnlineTomTomNavigationFactory.Configuration(
    3 locationProvider: customLocationProvider,
    4 routeReplanner: routeReplanner,
    5 apiKey: "YOUR_API_KEY"
    6)
    7let navigation = try OnlineTomTomNavigationFactory.create(configuration: configuration)
  3. Enable the provider to receive location updates.

    locationProvider.start()
  4. At any time the LocationProvider can be disabled to stop receiving location updates.

    locationProvider.stop()
  5. Location updates can be observed using the LocationProviderObservable protocol.

    1func onLocationUpdated(location: GeoLocation) {
    2 /* YOUR CODE GOES HERE */
    3}
    4
    5func onHeadingUpdate(newHeading: CLHeading, lastLocation: GeoLocation) {
    6 /* YOUR CODE GOES HERE */
    7}
    8
    9func 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)
  6. LocationProvider has a property with the last known GeoLocation.

    let lastLocation = locationProvider.location