'How to display title and snippet on a google maps composable marker, without clicking on it?
I'm using the new google maps integration library with jetpack compose, however I want to modify a behavior of my markers: when the map initializes I want to show the information of my marker without having to click on it. Currently the map starts like this:
When I click on the highlighted mark it looks like this:
The result I expect is that this bookmark appears with this information without me necessarily having to click on it.
The code I use to render the map with the markers is this:
GoogleMap(
modifier = Modifier
.fillMaxHeight(0.9f)
.fillMaxWidth(),
cameraPositionState = cameraPositionState
) {
coordinates.forEach { (hotelName, coordinate) ->
var alpha = 0.5f
if (highlightedMarkerPosition == LatLng(coordinate[0], coordinate[1]))
alpha = 1f
Marker(
position = LatLng(coordinate[0], coordinate[1]),
title = hotelName,
snippet = uiState.bestHotelAndValue?.second.toString(),
alpha = alpha
)
}
}
Solution 1:[1]
save the MarkerState
into a variable and then call showInfoWindow
like this
GoogleMap(
modifier = Modifier
.fillMaxHeight(0.9f)
.fillMaxWidth(),
cameraPositionState = cameraPositionState
) {
coordinates.forEach { (hotelName, coordinate) ->
var alpha = 0.5f
if (highlightedMarkerPosition == LatLng(coordinate[0], coordinate[1]))
alpha = 1f
HotelMarker(
LatLng(coordinate[0], coordinate[1]),
hotelName,
uiState.bestHotelAndValue?.second.toString(),
alpha
)
}
}
@Composable
fun HotelMarker(position: LatLng, title: String, snippet: String?, alpha: Float){
val markerState = rememberMarkerState(null, position)
Marker(
state = markerState,
title = title,
snippet = snippet,
alpha = alpha
)
markerState.showInfoWindow()
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |