Skip to main content

Custom location provider

In some cases, you might need to use your own source of location updates. For example, automotive OEMs may want to implement gathering GPS signals from an alternative hardware. In that case, you can build your custom location provider which must implement the DeviceLocationProvider interface, and then wrap it in a factory. In the code, it may look like this:

val config = DashConfig.create(
applicationContext = applicationContext,
accessToken = getString(R.string.mapbox_access_token)
) {
customLocationProviderFactoryConfig = CustomLocationFactoryProviderConfig.Builder(
LocationProviderFactory { _ ->
MyLocationProvider()
},
// The locations emitted by MyLocationProvider are real, so specify type REAL.
// If custom location provider is mocked or mixed, make sure it sets the correct isMock flag to mocked locations.
LocationProviderType.REAL,
).build()
}
Dash.init(config)

Where MyLocationProvider is the implementation of DeviceLocationProvider.

Was this page helpful?