Get current location button is not show on the jetpack compose google map

Viewed 676

I want to show the current location button (isMyLocationButtonEnabled) on the Google Map but it's not showing.

How can I display the get current location button?

AndroidView(
    factory = { mapView }
) {
    mapView.getMapAsync { map ->
        map.apply {
            navigatorViewModel.apply {
                viewModelScope.launch {
                    isMapEditable.collectLatest {
                        uiSettings.setAllGesturesEnabled(
                            it,
                        )
                        uiSettings.isMyLocationButtonEnabled = true
                    }
                }
                val location = lastSelectedLocation.value
                val position = LatLng(location.latitude, location.longitude)
                moveCamera(
                    CameraUpdateFactory.newLatLngZoom(
                        position,
                        Constants.ZOOM_CAMERA
                    )
                )

                setOnCameraIdleListener {
                    val cameraPosition = map.cameraPosition
                    updateLocation(
                        cameraPosition.target.latitude,
                        cameraPosition.target.longitude
                    )
                }
            }
        }
    }
}
2 Answers

Add these properties:

val uiSettings = remember {
    MapUiSettings(myLocationButtonEnabled = true)
}
val properties by remember {
    mutableStateOf(MapProperties(isMyLocationEnabled = true))
}

GoogleMap:

 GoogleMap(
    modifier = modifier.fillMaxSize(),
    cameraPositionState = cameraPositionState,
    properties = properties,
    uiSettings = uiSettings)

I'm replying so late, this answer might help someone else!

To show MyLocationButton in google map you need enable both map.isMyLocationEnabled = true & uiSettings.isMyLocationButtonEnabled = true

Related