在我的应用程序中,我展示了一个地图,并使用聚类标记了不同的区域,以便将最近的位置分组。但是我有一个问题。当我修改一些标记(例如使用名称搜索过滤器)时,标记并没有总是被更新。有时新的标记会被绘制,但几乎总是旧的标记还留在那里。我尝试了在重新添加标记之前清除它们,但这并不起作用。这是我的代码:
@Composable
fun MyMap(
locations: State<LocationData>
) {
lateinit var clusterManager: ClusterManager<LocationClusterItem>
val mapView = rememberMapViewWithLifeCycle()
val localContext = LocalContext.current
Column(
modifier = Modifier
.background(Color.White)
) {
AndroidView(
{
mapView
}
) {
mapView.getMapAsync {
val map = it
map.uiSettings.isZoomControlsEnabled = false
clusterManager = ClusterManager(localContext, map)
clusterManager.clearItems()
clusterManager.cluster()
map.setOnCameraIdleListener(clusterManager)
map.setOnMarkerClickListener(clusterManager)
for (location in locations.value.sites) {
clusterManager.addItem(IncidentClusterItem(location.lat, location.lon, location.street, location.info))
}
clusterManager.cluster()
map.moveCamera(
CameraUpdateFactory.newLatLngZoom(
LatLng(50.00000000000000, -10.000000000000000),
12f
)
)
map.mapType = GoogleMap.MAP_TYPE_HYBRID
}
}
}
}
怎样才能正确更新地图上的标记?