Route simulation
Request accessNavigation functionality depends on knowing the user’s location. Location updates are provided by the LocationProvider . To obtain 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. To use the LocationProvider that provides simulated locations, add the following dependency in the module’s build.gradle.kts.
implementation("com.tomtom.sdk.location:provider-simulation:1.26.4")SimulationLocationProvider
The SimulationLocationProvider simulates location updates using the provided list of locations. It implements the LocationProvider interface. To define the strategy for generating location updates a SimulationStrategy has to be provided to the constructor.
val timestampStrategy = TimestampStrategy(locations = locations)val simulationLocationProvider = SimulationLocationProvider.create(timestampStrategy)SimulationStrategy
SimulationLocationProvider requires a SimulationStrategy that determines how location updates should occur.
Two predefined strategies are available: InterpolationStrategy and TimestampStrategy. You can also create a custom strategy for providing simulated locations. To do this, implement the SimulationStrategy interface. The interface contains two methods:
-
SimulationStrategy.calculateLocation()- Calculates and returns aSimulationLocationto broadcast as the location update. -
SimulationStrategy.hasNext()- Determines if there are any remaining locations to be sent out.
InterpolationStrategy
InterpolationStrategy uses interpolation to determine a simulated position.
To create an InterpolationStrategy object, provide a list of GeoLocation that will be used during simulation. The rest of the parameters are optional. You can specify the delay after the first position is provided and the delay before the provision of each subsequent location. You can also define the speed of the moving object in meters per second.
val interpolationStrategy = InterpolationStrategy( locations = locations, startDelay = 1.seconds, broadcastDelay = 500.milliseconds, currentSpeed = metersPerSecond(13.0), )TimestampStrategy
TimestampStrategy calculates the delay between simulated locations based on the differences between GeoLocation.time in consecutive locations. This strategy is useful if you are using previously recorded traces, where the consecutive locations are closer to each other than for a route.
To create this object, provide a list of GeoLocation objects.
val timestampStrategy = TimestampStrategy( locations = locations, )Changing navigation location providers
The LocationProvider used for navigation is initially specified using the Configuration object. However, you can retrieve and change the LocationProvider 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.
val timestampStrategy = TimestampStrategy(locations = locations)val simulationLocationProvider = SimulationLocationProvider.create(timestampStrategy)tomTomNavigation.locationProvider = simulationLocationProviderNext steps
Since you have learned how to simulate a route, here are recommendations for the next steps: