MapFragment中出现“地图大小不能为0”的异常

问题描述

我正在使用自定义MapFragment,它正在显示地图。我实现了OnMapReadyCallback,以通知我的Fragment地图已准备就绪。然后,我将在地图上初始化绘图过程。这可以按预期工作,但是在最近的更新(可能是播放服务库)中,我想在地图上绘制标记/多边形时遇到了这个异常。

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 occured for the map view.

这很奇怪,因为绘制过程是在OnMapReadyCallback内部启动的,因此此时地图应该已经准备好了。如果我注释掉绘图过程,地图将完美加载。

这是库中的某个错误还是已更改?

代码示例:

override fun onCreateView(li: LayoutInflater,container: ViewGroup?,si: Bundle?): View? {
        return (li.inflate(R.layout.fragment_map,container,false) as ViewGroup).apply {
            val mf = childFragmentManager.findFragmentById(R.id.map) as? SupportMapFragment
            mf?.getMapAsync(this@MapFragment)
        }
    }

override fun onMapReady(p0: GoogleMap?) {
        map = p0
        map?.setInfoWindowAdapter(MarkerInfoView(markerInfoLayout,::onMarkerClickAction))
        initMapCalls(::drawRoute)
        initMapUpdater(REFRESH_RATE,::getMarkersPosition)
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)