User location

The Map Display Compose module allows you to show the current user location on the map. Location data is provided by the LocationProvider and is used to display the user location marker indicator on the map.

Using the location provider with the map

Location updates are generated by the LocationProvider. To receive them, you need to configure MapDisplayInfrastructure using an instance of LocationProvider. It will be used by the map to position the location marker according to the position updates.

val mapDisplayInfrastructure = MapDisplayInfrastructure(TomTomSdk.sdkContext) {
locationInfrastructure = MapLocationInfrastructure {
locationProvider = myLocationProvider
}
}

You can also use the LocationState from the MapViewState instance to retrieve the current user location or check whether the location marker is visible on the screen.

Note that if the LocationProvider was not set, or if it did not provide any location data, the current location will not be available.

val isLocationInVisibleArea = mapViewState.locationState.isCurrentLocationInMapBoundingBox()
val currentLocation: GeoLocation? = mapViewState.locationState.getCurrentLocation()

Location marker

The user location is shown as a CurrentLocationMarker on the map.

TomTomMap(
infrastructure = mapDisplayInfrastructure,
state = mapViewState,
) {
CurrentLocationMarker(
properties = CurrentLocationMarkerProperties {
type = Type.Chevron
},
)
}

The location marker is displayed as shown below.

Chevron

Next steps

Since you have learned how to show user locations, here are recommendations for the next steps: