We have developed an application using Compose and using version 5.0.1 for the map screen and to add markers.
After moving and stopping, we make a request to the server and receive a response with a list of markers. We map these to the UI model and try to draw them on the map as shown below:
GoogleMap(
modifier = modifier,
cameraPositionState = cameraPositionState,
properties = mapProperties,
uiSettings = uiSettings,
onMapClick = { onMapClick() },
onMapLoaded = {
onMapLoaded(
LocationLatLng(
cameraPositionState.position.target.latitude,
cameraPositionState.position.target.longitude
),
cameraPositionState.visibleAreaAsRadius(defaultVisibleAreaDistance)
)
}
) {
markers?.forEach { marker ->
MarkerComposable(
state = rememberMarkerState(
key = marker.key,
position = LatLng(
marker.position.latitude,
marker.position.longitude
),
),
onClick = {
marker.onMarkerClick()
return@MarkerComposable false
}
) {
Image(
modifier = Modifier.size(64.dp),
painter = painterResource(marker.iconResId),
contentDescription = marker.contentDescriptionResId?.let { stringResource(it) },
)
}
}
}
...
}
However, I sometimes notice that even if the markers are in the list, they do not get drawn on the map screen. What could be the reason for this?
Thanks in advance.
Note: Marker keys are unique.
I would expect that markers appearing on the map are displayed on the map screen as I move it. The marker does not appear after entering rememberMarkerState, it doesn't recompose.
markers
list is defined & initialized with the data?