Jetpack Compose 谷歌地图上的“获取当前位置”按钮未显示。

4

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

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

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个回答

8

添加以下属性:

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

Google地图:

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

1

很抱歉回复晚了,这个答案可能会帮助其他人!

要在谷歌地图中显示“我的位置”按钮,您需要启用以下两个选项:map.isMyLocationEnabled = trueuiSettings.isMyLocationButtonEnabled = true


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接