CustomLocationDataSource

A LocationDataSource that can be driven by a user-defined provider of location data. This can be useful if you have location data coming in from some custom source and you would like that data in the form of a LocationDataSource so that it can interface with other parts of the API.

This class will create an instance of LocationProvider using createLocationProvider when the data source is LocationDataSourceStatus.Starting. The resulting LocationProvider can be obtained from CustomLocationDataSource.currentProvider, which will be null when the data source is not LocationDataSourceStatus.Started. A new LocationProvider instance is created every time the data source is started.

Note that this API does not provide status updates to the LocationProvider. If you use a SharedFlow, be aware that it will continue emitting after the CustomLocationDataSource is stopped. The CustomLocationDataSource will stop collecting when CustomLocationDataSource.stop is called, at which point it will no longer be a subscriber to the SharedFlow. Refer to the official documentation of Flow and SharedFlow for more information on how to observe collectors from the emission source.

Since

200.0.0

See also

Constructors

Link copied to clipboard
constructor(createLocationProvider: suspend () -> CustomLocationDataSource.LocationProvider)

Types

Link copied to clipboard

An interface containing Flows through which you can provide location and heading updates to a CustomLocationDataSource.

Properties

Link copied to clipboard

The current LocationProvider which is providing locations and headings to this CustomLocationDataSource.

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.

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.