SimulatedLocationDataSource

A location data source that provides simulated device locations for testing. Use this data source to simulate location updates for a device. It uses a collection of Location that are sequentially passed to LocationDataSource.updateLocation(Location). The location collection can be derived from vertices in a provided polyline, generated evenly along a polyline based on a travel velocity, or assigned to the collection directly.

Since

200.1.0

Constructors

Link copied to clipboard
constructor()

Creates a simulated location data source.

constructor(locations: Iterable<Location>)

Creates a simulated location data source with the specified locations.

constructor(polyline: Polyline, parameters: SimulationParameters? = null)

Creates a simulated location data source which derives its collection of locations along an input polyline, optionally based on simulation parameters.

Properties

Link copied to clipboard

The index of the item in the location collection that provides the current location. You can get this value to find which item in the SimulatedLocationDataSource.locations collection represents the current location. You can also provide a new index to skip to a different location in the collection.

Link copied to clipboard

The rate over which the SimulatedLocationDataSource.locations collection is iterated. This controls the frequency of location updates for the simulated location data source. The default value is 1.0, resulting in calls to LocationDataSource.updateLocation(Location) every second. To increase the frequency, provide a higher value. A value of 2.0, for example, doubles the frequency of location updates. To slow down updates, provide a lower value. A value of 0.5, for example, decreases location updates by a factor of two. The iteration rate does not affect the Location.timestamp property of the items in the SimulatedLocationDataSource.locations (they are always 1 second apart).

Link copied to clipboard

A collection of locations that are iterated sequentially. As the collection is iterated, the LocationDataSource.updateLocation(Location) is fired for each location. The frequency at which LocationDataSource.updateLocation(Location) is called is determined by SimulatedLocationDataSource.iterationRate. Populate the collection by calling SimulatedLocationDataSource.setLocationsWithPolyline(Polyline) or by directly assigning a collection of Location to this property.

Inherited properties

Link copied to clipboard
val error: StateFlow<Throwable?>

An error that describes a problem encountered while starting or running the LocationDataSource. This property is used to notify the user about errors that occur in LocationDataSource. Such errors are critical for LocationDataSource and will cause it stop. If LocationDataSource cannot be started, or it stopped after a successful start, this property will store information related to what caused LocationDataSource to stop.

Link copied to clipboard
val headingChanged: SharedFlow<Double>

Set the heading changed callback function for the location data source.

Link copied to clipboard
open val locationChanged: SharedFlow<Location>

A SharedFlow that emits location changes.

Link copied to clipboard

The current status of the location data source. The status indicates if the location data source is starting, started, stopping, stopped, and has failed to start.

Functions

Link copied to clipboard

Creates a collection of locations using vertices from an input polyline. The generated locations are available from the SimulatedLocationDataSource.locations property. These location properties are populated based on the inputs: Location.timestamp, Location.position, Location.speed, The Location.course property is calculated based on the inputs. These location properties are not set: Location.horizontalAccuracy, Location.verticalAccuracy, Location.lastKnown

fun setLocationsWithPolyline(polyline: Polyline, simulationParameters: SimulationParameters)

Creates a collection of locations along an input polyline based on simulation parameters. The generated locations are available from the SimulatedLocationDataSource.locations property. Distance between each location on the polyline is determined by the value of SimulationParameters.velocity. If velocity is 10 meters per second, for example, the distance between locations will be 10 meters. The Location.timestamp values will always be 1 second apart. These location properties will be set based on the inputs: Location.timestamp, Location.position, Location.speed, Location.horizontalAccuracy, Location.verticalAccuracy The Location.course property will be calculated based on the inputs and the Location.lastKnown property will not be set.

Inherited functions

Link copied to clipboard
suspend fun start(): Result<Unit>

Starts the location data source asynchronously and prepares to begin receiving location updates.

Link copied to clipboard
suspend fun stop(): Result<Unit>

Stop the location data source asynchronously.