Create your own provider

VERSION 0.54.0

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 navigationTileStore: try NavigationTileStore(config: NavigationTileStoreConfiguration(apiKey: "YOUR_TOMTOM_API_KEY")),
    4 locationProvider: customLocationProvider,
    5 routePlanner: routePlanner
    6)
    7let navigation = try OnlineTomTomNavigationFactory.create(configuration: configuration)
  3. Send authorization request by calling requestWhenInUseAuthorization() or requestAlwaysAuthorization() on the CLLocationManager instance respectively. Complete instructions to request location permissions on iOS can be found at Requesting authorization for location services.

    let locationManager = CLLocationManager()
    locationManager.requestWhenInUseAuthorization()
  4. Enable the provider to receive location updates.

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

    locationProvider.disable()
  6. Location updates can be observed using the LocationUpdateObserver protocol.

    1func didUpdateLocation(location: GeoLocation) {
    2 /* YOUR CODE GOES HERE */
    3}

    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)
  7. LocationProvider has a property with the last known GeoLocation.

    let lastLocation = locationProvider.lastKnownLocation