Create your own engine

VERSION 0.2.1455
PUBLIC PREVIEW

Within the TomTom SDKs, developers are not limited to the provided location engines. They can also use their own implementations of the LocationEngine 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 engine implements the LocationEngine protocol 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 Map User Location. The engine is also used by the Navigation module to configure navigation.

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

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

    1let customLocationEngine = DefaultCLLocationEngine()
    2let configuration = NavigationConfigurationBuilder(
    3 navigationKey: "<NAVIGATION-KEY>",
    4 locationEngine: customLocationEngine,
    5 routingService: routingService
    6)
    7.build()
    8let navigation = Navigation(configuration: configuration)
  3. Enable the engine to receive location updates.

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

    locationEngine.stop()
  5. Location updates can be observed using the LocationEngineObserver 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 LocationEngine instance observers. Remember to remove the observer if it is no longer needed.

    locationEngine.addObserver(self)
    locationEngine.removeObserver(self)
  6. LocationEngine has a property with the last known GeoLocation.

    let lastLocation = locationEngine.location