将Android GoogleMap集群化非常慢

时间:2018-10-30 06:23:43

标签: android google-maps

我在我的应用程序中集成了集群。在onBeforeClusterItemRendered方法中为单个项目添加自定义图像会导致应用卡住一段时间。问题仅在Android 8设备上。

override fun onBeforeClusterItemRendered(item: MarkerItem?, markerOptions: MarkerOptions?) {
        val iconType = getMarkerIcon(item!!.mapObjectType, item!!.markerType)

        setMarkerIcon(mapObjectSelection, item.mapObjectType, markerOptions, iconType, 0, false)



    }




 private fun setMarkerIcon(currentTableSelection: Int, mapObjectType: Int, markerOptions: MarkerOptions?, iconType: Int, markerCount: Int, isClusterIcon: Boolean) {

 if (isClusterIcon) {
            val icon = mMapIconGenerator.makeIcon(iconType, tempMarkerCount)
            markerOptions?.icon(BitmapDescriptorFactory.fromBitmap(icon))
        } else {

            var bitmap = mapIcons[iconType]

            if(null == bitmap){
                bitmap = BitmapFactory.decodeResource(mContext.resources,iconType)
                mapIcons[iconType] = bitmap
            }


        }

1 个答案:

答案 0 :(得分:0)

自定义图像尺寸很大,导致群集卡死。通过缩小地图图标图像的大小来解决