Cluster Manager无法将自定义图标分配给MarkerOptions

时间:2018-03-07 20:42:16

标签: google-maps kotlin google-maps-markers

我正在使用Google Maps Utils对标记进行分组。现在我想自定义群集图标并执行此操作我正在使用此代码

class ClusteredMarkerRender(context: Context, map: GoogleMap, clusterManager: ClusterManager<ClusteredMarker>)
    : DefaultClusterRenderer<ClusteredMarker>(context, map, clusterManager) {

    override fun onBeforeClusterRendered(cluster: Cluster<ClusteredMarker>?, markerOptions: MarkerOptions?) {
        super.onBeforeClusterRendered(cluster, markerOptions)

        markerOptions!!.icon = BitmapDescriptorFactory.fromResource(R.id.cluster_icon)
    }

    override fun shouldRenderAsCluster(cluster: Cluster<ClusteredMarker>?): Boolean {
        return cluster!!.size > 1
    }
}

但在markerOptions!!.icon Android Studio上说val cannot be reassigned。我该如何将自定义图标分配给markerOptions实例?

1 个答案:

答案 0 :(得分:0)

正如asm0dey所说,分配图标的正确方法是

minOccurs="0"