I'm trying to update the InfoWindowMarker
content of my Google map in Compose
, for that, I added a onClick
to the InfoWindowMarker
and when it's clicked, it changes a "favorite" variable which is hoisted on the map. That favorite variable is passed to the marker, and depending of that variable shows or not another Text.
The problem is that when the marker is pressed, the variable is changed (I tested it under debug mode with a breakpoint) but the info window is not changed! the favorite Text doesn't appear, it's like it's not being recomposed.
This is my Google map:
GoogleMap(
modifier = Modifier.fillMaxSize(),
cameraPositionState = cameraPositionState
) {
val bitmapDescriptor: BitmapDescriptor by remember { mutableStateOf(BitmapDescriptorFactory.fromResource(R.drawable.place)) }
for (busStop in uiState.data) {
var favorite by remember { mutableStateOf(false) }
val markerState = rememberMarkerState(position = LatLng(busStop.lat, busStop.lon))
CustomMarker(
favorite = favorite,
busStop = busStop,
markerState = markerState,
bitmapDescriptor = bitmapDescriptor,
showMarker = showMarkers,
onMarkerClicked = { favorite = !favorite }
)
}
}
This is my CustomMarker:
@Composable
fun CustomMarker(
favorite: Boolean,
busStop: BusStop,
markerState: MarkerState,
bitmapDescriptor: BitmapDescriptor,
showMarker: Boolean,
onMarkerClicked: () -> Unit,
modifier: Modifier = Modifier
) {
MarkerInfoWindowContent(
state = markerState,
icon = bitmapDescriptor,
visible = (showMarker),
onInfoWindowClick = {
onMarkerClicked()
}
) {
Column(
modifier = modifier.wrapContentSize().padding(8.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = busStop.id.toString(), color = Color.Red)
Text(text = busStop.name, color = Color.Red)
if (favorite)
Text("favorite"}
}
}
}