Simulation location provider


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.



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)


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:


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 =
2 InterpolationStrategy(
3 locations = locations,
4 startDelay = 1.seconds,
5 broadcastDelay = 500.milliseconds,
6 currentSpeed = metersPerSecond(13.0),
7 )


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.

Location simulation based on the TimestampStrategy only works if the timestamps of the GeoLocation sequence are valid.

To create this object, provide a list of GeoLocation objects.

1val timestampStrategy =
2 TimestampStrategy(
3 locations = locations,
4 )

Next steps

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