我正试着和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正确工作,控制它的生命和负载,我将永远感激. 谢谢