Route simulation

VERSION 0.45.0
PUBLIC PREVIEW

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

SimulatedLocationProvider

Navigation functionality depends on knowing the user’s location.

Location updates are provided by the LocationProvider. To obtain user location, you can use the default location provider or set a custom provider.

Location updates along a route can also be simulated for testing purposes.

Construction

The SimulatedLocationProvider implements 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 will be used. If no delay is set, a timestamp-based simulation strategy will be 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 can be 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 if the location provider should use interpolation or not. When updating coordinates with a gpx file or ttp file, the default is false. When updating coordinates with an array of coordinates the default is true. 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.

Changing navigation location provider

The LocationProvider used for navigation is initially specified when TomTomNavigation is initialized. However, you can change the provider responsible for location updates at any time. For example, you can switch to simulated locations even if the navigation was started with the user location.

1var navigation = try OnlineTomTomNavigationFactory.create(configuration: configuration)
2try navigation.start()
3let simulatedLocationProvider = SimulatedLocationProvider(delay: Measurement<UnitDuration>(value: 0.5, unit: .seconds))
4navigation.locationProvider = simulatedLocationProvider

Next steps

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