Simulation location provider
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
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)
Two predefined strategies are available:
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 a
SimulationLocationto broadcast as the location update.
SimulationStrategy.hasNext()- Determines if there are any remaining locations to be sent out.
InterpolationStrategy uses interpolation to determine a simulated position.
It 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.
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.
1val interpolationStrategy = InterpolationStrategy(2 locations = locations,3 startDelay = 1.seconds,4 broadcastDelay = 500.milliseconds,5 currentSpeed = metersPerSecond(13.0)6)
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
1val timestampStrategy = TimestampStrategy(2 locations = locations3)
Since you have learned how to simulate a route, here are recommendations for the next steps: