我正在使用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
安卓工作室说val cannot be reassigned
.如何将自定义图标分配给markerOptions
实例?
正如asm0dey所说,分配图标的正确方法是
markerOptions!!.icon(BitmapDescriptorFactory.fromResource(R.id.cluster_icon))