googlemaps / googlemaps/android-maps-compose

When two markers are close to each other, clicking on the exact same spot won’t always trigger the same marker, and it gets worse if z-indexes are involved

Aperta
#455 6 commenti 10 reazioni 0 assegnatari Vedi su GitHub
needs more info priority: p2 type: bug
Lingua principale
Kotlin
Stelle
1.3k
Fork
181
Merge medio
2g 23h
PR unite (30g)
18

Descrizione

I’ve reproduced the issue on a Pixel 4a and Zenfone 10 both running Android 13.

- Run the sample and tap on the “Marker Clustering” button. Lots of markers there, so it’s a good place to reproduce the issue.
- Reach a zoom level where you get two markers close to each other, something like this:

![asd](https://github.com/googlemaps/android-maps-compose/assets/750114/9ab34e33-68ea-45a0-899c-b9bb28752508)

- Keep tapping on an isolated point in one of the markers, where there shouldn’t be any doubts about which marker is being tapped, and then observe that clicking on the same point will sometimes trigger one marker, and sometimes the other:

https://github.com/googlemaps/android-maps-compose/assets/750114/f1456ded-dc01-4efb-ad0b-cb952ce30e5f

- This is weird but it’s not so bad. I guess this may actually be an accessibility feature so it’s easy to switch back and forth between nearby markers? It gets more interesting if the markers have z-indexes set, so let’s observe this again with custom markers this time. You can run the code below within the sample:

```kotlin
val markers = listOf(LatLng(51.721695, 10.393405), LatLng(51.824536, 10.537953))
var highlightedMarkerIndex by remember { mutableIntStateOf(0) }
val cameraPositionState = rememberCameraPositionState {
position = CameraPosition.fromLatLngZoom(markers[highlightedMarkerIndex], 7.5f)
}

Box(Modifier.fillMaxSize()) {
GoogleMap(
modifier = Modifier.fillMaxSize(),
cameraPositionState = cameraPositionState,
) {
markers.forEachIndexed { index, marker ->
MarkerComposable(
highlightedMarkerIndex,
state = rememberMarkerState(position = marker),
anchor = Offset(0.5f, 0.5f),
onClick = {
highlightedMarkerIndex = index
true
}
) {
Box(
modifier = Modifier
.size(32.dp)
.background(if (index == highlightedMarkerIndex) Color.Red else Color.Gray),
)
}
}
}
}
```

- And observe the same thing there. It’s just a map with two square markers and whenever a marker is tapped, it becomes red:

https://github.com/googlemaps/android-maps-compose/assets/750114/59b41ca2-4d52-4e22-85ed-b0cadebc7f41

- Now let’s make the highlighted marker always be on top by passing `zIndex = if (index == highlightedMarkerIndex) 1f else 0f`, and here’s where the experience really starts feeling broken: now in order to highlight the non-highlighted marker, you have to tap twice.

https://github.com/googlemaps/android-maps-compose/assets/750114/8a8be3c5-90ff-4910-a21f-842768579f8d

I went through multiple examples to try to explain all the weirdnesses I've identified while investigating this, but this last part is the real issue to me. We're highlighting markers and making sure the highlighted marker has a higher z-index, but this is causing the first tap to a nearby marker to be ignored as it's demonstrated above.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con il pulsante “Marker Clustering” dell’esempio e riproduci il comportamento usando marker MarkerComposable, quindi confronta i tap con e senza lo zIndex del marker evidenziato. Verifica la correzione assicurandoti che un tap su un marker vicino non evidenziato lo selezioni al primo tentativo, anche quando il marker evidenziato viene renderizzato sopra di esso.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
android, kotlin
Ambito
mobile
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.