[Android] onMarkerClick reports the marker's coordinate as the press position instead of the touch point (tapLocation is already captured)
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 88/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- android, java, react-native
- Área
- mobile-dev
Línea de trabajo
Comienza en android/src/main/java/com/rnmaps/maps/MapView.java, leyendo dispatchTouchEvent y el controlador onMarkerClick para ver cómo se captura tapLocation y cómo lo utilizan los eventos de polígonos y polilíneas. Verifica que el evento del marcador informe de forma coherente el punto tocado con esos controladores, usando la prueba instrumentada de eventos de puntero de ReactHost descrita en el issue.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
On Android, a marker press reports the marker's coordinate as the event's coordinate/position, not the point the user actually touched. MapView.onMarkerClick calls makeClickEventData(marker.getPosition()). The touch point is already captured in dispatchTouchEvent as tapLocation, and the polygon and polyline click handlers already use it; markers are the odd one out.
This matters because Google Maps' hit region for custom image markers is offset and oversized (measured on a Samsung A13: a finger dead-centre on pin b is reported as the pin beside it, and a tap on empty map ~30dp above a pin counts as that pin). An app that wants to resolve the tap itself against the drawn pin shapes needs the finger position, and today the payload throws it away.
Reproducible sample code
<Marker
coordinate={{ latitude: -41.29, longitude: 174.78 }}
image={require('./pin.png')}
onPress={(e) => console.log(e.nativeEvent.coordinate, e.nativeEvent.position)}
/>
Steps to reproduce
Tap the marker off-centre (e.g. its top-right corner).
Expected result
coordinate/position describe the touched point, as they do for MapView.onPress, polygons and polylines.
Actual result
They are exactly the marker's own coordinate, whatever was touched.
Fix
--- a/android/src/main/java/com/rnmaps/maps/MapView.java
+++ b/android/src/main/java/com/rnmaps/maps/MapView.java
@@ -572,12 +572,14 @@
public boolean onMarkerClick(@NonNull Marker marker) {
MapMarker airMapMarker = getMarkerMap(marker);
- WritableMap eventData = makeClickEventData(marker.getPosition());
+ // Report the touched point (already captured in dispatchTouchEvent),
+ // as polygon/polyline presses do.
+ LatLng pressLoc = tapLocation != null ? tapLocation : marker.getPosition();
+ WritableMap eventData = makeClickEventData(pressLoc);
eventData.putString("action", "marker-press");
eventData.putString("id", airMapMarker.getIdentifier());
airMapMarker.dispatchEvent(eventData, OnPressEvent::new);
- WritableMap mapEventData = makeClickEventData(marker.getPosition());
+ WritableMap mapEventData = makeClickEventData(pressLoc);
mapEventData.putString("action", "marker-press");
mapEventData.putString("id", airMapMarker.getIdentifier());
If keeping the marker's coordinate in coordinate is preferred for compatibility, an additional field carrying the touch point would serve the same purpose.
React Native Maps Version
1.29.0 (present on master, v1.29.2)
What platforms are you seeing the problem on?
Android
React Native Version
0.86 (Expo SDK 57), New Architecture
Device(s)
Samsung A13, Pixel 9 Pro, arm64 emulator (API 36)
Additional information
Verified with an instrumented test on the app's own ReactHost that injects real pointer events and reads the JS payload back. A full write-up will be at https://zackdesign.biz/which-pin-did-you-tap/ shortly.
- Lenguaje dominante
- TypeScript
- Estrellas
- 16k
- Forks
- 5k
- Merge medio
- 17 h 45 min
- PR fusionados (30 d)
- 2
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de react-native-maps/react-native-maps
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
react-native-maps/react-native-maps#5987 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
react-native-maps/react-native-maps#5977 · 2 comentarios · 1 reacción ·
Todos los issues de react-native-maps/react-native-maps
Issues similares
-
blocklist removal
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
MetaMask/eth-phishing-detect#296544 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
pastelsky/bundlephobia#1122 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
category/development priority/P2 scope/file-operations scope/testing type/enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100