MapStateProvider

Interface for providing map state and controller to Android Auto.

This interface abstracts the mechanism by which Android Auto obtains the MapController and cached position from the phone application. It allows different applications to implement their own state sharing mechanism.

Purpose

  • Decoupling: Separates Android Auto module from specific app implementations

  • Flexibility: Apps can use Hilt, manual injection, or other DI frameworks

  • Reusability: The same Android Auto module works with different apps

Usage

Applications should implement this interface to provide the MapController and cached position when Android Auto requests them:

class MyMapStateProvider : MapStateProvider {
private var mapController: MapController? = null
private var cachedPosition: GeoPoint? = null

override fun getMapController(): MapController? = mapController
override fun getCachedInitialPosition(): GeoPoint? = cachedPosition
override fun hasMapController(): Boolean = mapController != null

fun setMapController(controller: MapController?) {
mapController = controller
}

fun setCachedInitialPosition(position: GeoPoint?) {
cachedPosition = position
}
}

See also

Inheritors

Functions

Link copied to clipboard

Gets the cached initial position for instant map centering.

Link copied to clipboard

Gets the MapController for controlling the map from Android Auto.

Link copied to clipboard
abstract fun hasMapController(): Boolean

Checks if a MapController is available.