Route simulation
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.geometryengineUpdatedWithCoordinates.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:
timeStampBasedEngine.updateLocationsFromTTPFile(path: "<PATH>", interpolate: true)delayBasedEngine.updateCoordinatesFromGPXFile(path: "<PATH>", interpolate: true)engineUpdatedWithCoordinates.updateCoordinates(coordinates, interpolate: false)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.
var navigation = try OnlineTomTomNavigationFactory.create(configuration: configuration)try navigation.start()let simulatedLocationProvider = SimulatedLocationProvider(delay: Measurement<UnitDuration>(value: 0.5, unit: .seconds))navigation.locationProvider = simulatedLocationProviderNext steps
Since you have learned how to simulate a route, here are recommendations for the next steps: