我正试着和MapView分合作,

使用NavController时,我几乎可以自动导航,但当我返回(navigateUp())并必须加载 map 时,我收到以下错误

com.google.maps.api.android.lib6.common.apiexception.c: Error using newLatLngBounds(LatLngBounds, int): Map size can't be 0. Most likely, layout has not yet occurred for the map view.  Either wait until layout has occurred or use newLatLngBounds(LatLngBounds, int, int, int) which allows you to specify the map's dimensions.
                                                                                                        at com.google.maps.api.android.lib6.common.m.h(:com.google.android.gms.dynamite_mapsdynamite@233918037@23.39.18 (150400-0):8)
                                                                                                        at com.google.maps.api.android.lib6.gmm6.api.c.l(:com.google.android.gms.dynamite_mapsdynamite@233918037@23.39.18 (150400-0):28)
                                                                                                        at com.google.maps.api.android.lib6.impl.ae.a(:com.google.android.gms.dynamite_mapsdynamite@233918037@23.39.18 (150400-0):10)
                                                                                                        at com.google.maps.api.android.lib6.gmm6.api.c.z(:com.google.android.gms.dynamite_mapsdynamite@233918037@23.39.18 (150400-0):31)
                                                                                                        at com.google.maps.api.android.lib6.impl.bk.q(:com.google.android.gms.dynamite_mapsdynamite@233918037@23.39.18 (150400-0):25)
                                                                                                        at com.google.android.gms.maps.internal.i.bb(:com.google.android.gms.dynamite_mapsdynamite@233918037@23.39.18 (150400-0):1959)
                                                                                                        at m.fi.onTransact(:com.google.android.gms.dynamite_mapsdynamite@233918037@23.39.18 (150400-0):21)

我知道使用SupportMapFragment比较容易,因为一切都是自动化的,但我想知道为什么我会有这个错误.

我已经实现了以下方法:

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mapView = binding.root.findViewById(R.id.gm_resource)
        mapView.onCreate(savedInstanceState)
        mapView.getMapAsync(this)
    }
override fun onMapReady(p0: GoogleMap) {
        map = p0
        map.uiSettings.isMyLocationButtonEnabled = false
        map.mapType = GoogleMap.MAP_TYPE_SATELLITE
        map.setOnMapClickListener { requireContext().hideKeyboard(binding.root) }
        createClusterManager(map)
        loadResources()
        mapFocus(false)
        moveToolbar()
    }

我也试着控制MapView人的生活

override fun onResume() {
        mapView.onResume()
        super.onResume()
    }

    override fun onDestroy() {
        mapView.onDestroy()
        super.onDestroy()
    }

    override fun onLowMemory() {
        mapView.onLowMemory()
        super.onLowMemory()
    }

我不知道这是不是正确的方式,如果有人知道如何让mapView正确工作,控制它的生命和负载,我将永远感激. 谢谢

推荐答案

试着放一个SupportMapFragment,它更直观,更容易操作,这样它就不会给你带来这些麻烦

Android相关问答推荐

view喷气背包中找不到模型组成

处理Room数据库中的嵌套实体

在Jetpack Compose中,material 3 Textfield上的底部边框 colored颜色 是如何更改的?

Jetpack编写使用自定义主题覆盖库中主题部分

Android事件:APP_SCOUT_HANG警告SQLite

如何将Unicode符号作为文本居中放置在布局中的按钮(Android XML)中?

是否可以附加事件处理程序,如onClick,拖动到Canvas Composable中绘制的内容,或使用drawBehind修饰符?

当提供非状态对象时,compose 如何进行重组

返回并再次打开webview时webview无法打开相机

AndroidX Media3 迁移指南

如何在 compose 中使用可变对象?

Jetpack Compose:在屏幕外制作长水平图像的动画

Android 设备断开连接后发送的 BLE 蓝牙数据

获取 ArithmeticException:除以零,但我没有在任何地方除以零

Jetpack Compose 部分或开放侧边框

我该怎么做文本计时器

组成不重叠的元素

GridLayout 和 GridView 有什么好用和区别

如何使用jetpack compose实现布局,其中图标在列布局上是绝对位置

如何让用户与任意应用程序共享文件?