Simulation location provider

VERSION 0.45.0
PUBLIC PREVIEW

The Navigation SDK for iOS is only available upon request. Contact us to get started.

SimulatedLocationProvider

Location updates are provided by the LocationProvider. To obtain a user location, you can use the Built-in Location Providers or implement your own. Location updates along a route can also be simulated for testing purposes.

Construction

The SimulatedLocationProvider implements the LocationProvider. Upon construction the delay of the location updates can be set. The delay will be set in seconds. If a delay is set, a delay-based simulation strategy is used. If no delay is set, a timestamp-based simulation strategy is used.

The delay-based strategy gives every next location update after the provided delay (in seconds). The timestamp-based strategy uses the difference in time between the timestamps associated with the coordinates to decide the pace of updates. For timestamp-based simulation, use a TTP file to update the coordinates.

To create the simulated location provider, use:

let timeStampBasedProvider = SimulatedLocationProvider(delay: nil)
let delayBasedProvider = SimulatedLocationProvider(delay: Measurement<UnitDuration>(value: 0.5, unit: .seconds))

Updating coordinates

The provider simulates location updates using the provided locations. Locations are provided by calling SimulatedLocationProvider.updateCoordinates(_:interpolate:) with an array of coordinates. For example, the geometry of a Route can be used.

let coordinates: [CLLocationCoordinate2D] = route.geometry
engineUpdatedWithCoordinates.updateCoordinates(coordinates)

Locations can also be provided using a TTP file or a GPX file:

timeStampBasedEngine.updateLocationsFromTTPFile(path: "<TTP_FILE_PATH>")
delayBasedEngine.updateCoordinatesFromGPXFile(path: "<GPX_FILE_PATH>")

Interpolation

When updating the coordinates, it is possible to define whether the location provider should use interpolation or not. The default is false when updating coordinates with a GPX or TTP file. The default is true when updating coordinates with an array of coordinates. To override the default setting, use:

1timeStampBasedEngine.updateLocationsFromTTPFile(path: "<PATH>", interpolate: true)
2delayBasedEngine.updateCoordinatesFromGPXFile(path: "<PATH>", interpolate: true)
3engineUpdatedWithCoordinates.updateCoordinates(coordinates, interpolate: false)

Interpolation should be used if the successive locations are not close enough together. The main use case of this strategy is simulating from a route, because the coordinates are too far away from each other for smooth rendering.

Next steps

Since you have learned how to simulate a route, here are recommendations for the next steps: