Pablo
02/08/2025, 11:27 AMInfoWindowMarker
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. That favorite variable is passed to the InfoWindowMarker
composable, 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 breakpoing) but the info window is not changed, the favorite Text doens't appear, it's like its not being recomposed.Pablo
02/08/2025, 11:28 AMGoogleMap(
modifier = Modifier.fillMaxSize(),
cameraPositionState = cameraPositionState
) {
val bitmapDescriptor: BitmapDescriptor by remember { mutableStateOf(BitmapDescriptorFactory.fromResource(R.drawable.place)) }
for (item in uiState.data) {
var favorite by remember { mutableStateOf(false) }
val markerState = rememberMarkerState(position = LatLng(item.lat, item.lon))
CustomMarker(
favorite = favorite,
item = item,
markerState = markerState,
bitmapDescriptor = bitmapDescriptor,
showMarker = showMarkers,
onMarkerClicked = { favorite = !favorite }
)
}
}
This is my CustomMarker:
@Composable
fun CustomMarker(
favorite: Boolean,
item: Item,
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 = item.id.toString(), color = Color.Red)
Text(text = item.name, color = Color.Red)
if (favorite)
Text("favorite"}
}
}
}
Chrimaeon
02/08/2025, 2:08 PMPablo
02/08/2025, 2:32 PMChrimaeon
02/08/2025, 2:32 PMChrimaeon
02/08/2025, 2:33 PMPablo
02/08/2025, 2:34 PMPablo
02/08/2025, 2:35 PMChrimaeon
02/08/2025, 2:35 PMChrimaeon
02/08/2025, 2:39 PM