获取当前位置按钮未显示在 jetpack 撰写谷歌地图上

Sae*_*adi 4 android google-maps kotlin android-jetpack-compose

我想isMyLocationButtonEnabled在 Google 地图上显示当前位置按钮 ( ),但它没有显示。

如何显示获取当前位置按钮?

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
                    )
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 9

添加这些属性:

val uiSettings = remember {
    MapUiSettings(myLocationButtonEnabled = true)
}
val properties by remember {
    mutableStateOf(MapProperties(isMyLocationEnabled = true))
}
Run Code Online (Sandbox Code Playgroud)

谷歌地图:

 GoogleMap(
    modifier = modifier.fillMaxSize(),
    cameraPositionState = cameraPositionState,
    properties = properties,
    uiSettings = uiSettings)
Run Code Online (Sandbox Code Playgroud)