Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

onPress/onLongPress `position` is in device pixels on Android, points on iOS

Đang mở Phù hợp với người mới
#5,998 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
android, java, react-native
Lĩnh vực
mobile

Hướng nghiên cứu

Bắt đầu trong phần triển khai Android tại MapView.makeClickEventData(), sau đó so sánh cách xử lý projection.toScreenLocation(point) với MapModule.pointForCoordinate(), vốn đã chuẩn hóa kết quả. Xác minh vị trí sự kiện trên một thiết bị Android có mật độ khác 1 và xác nhận rằng onPress, onLongPress, onPanDrag, onPoiClick và thao tác nhấn vào marker sử dụng cùng đơn vị với iOS.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

Map events that carry a position (onPress, onLongPress, onPanDrag, onPoiClick, marker presses) report it in device pixels on Android and in UIKit points on iOS. Anything an app positions from that value — a context menu, a tooltip, a custom callout — therefore lands PixelRatio.get() times too far right and down on Android. On a 420 dpi device that is 2.625x, which is usually far enough to leave the screen.

docs/mapview.md documents these props as { coordinate: LatLng, position: Point } without stating a unit, so there is nothing that says which platform is right — but the two disagree, and the library itself is not consistent either: MapModule.pointForCoordinate() divides by the display density before resolving its promise, so the two ways of getting a frame point out of the same map answer in different units.

Version

react-native-maps 1.27.2, also present on master (1.29.0) and on beta.

Steps to reproduce

  1. Render a MapView with provider={PROVIDER_GOOGLE} on an Android device whose density is not 1.
  2. In onLongPress, store nativeEvent.position and absolutely position a small view at that {x, y}.
  3. Long-press somewhere near the middle of the map.

Expected: the view appears under the finger, as it does on iOS.
Actual: it appears at position * density — down and to the right, usually clamped at the edge of the screen.

Cause

MapView.makeClickEventData() puts projection.toScreenLocation(point) into the event as is:

Projection projection = map.getProjection();
Point screenPoint = projection.toScreenLocation(point);

WritableMap position = new WritableNativeMap();
position.putDouble("x", screenPoint.x);
position.putDouble("y", screenPoint.y);

toScreenLocation() answers in device pixels. MapModule.pointForCoordinate(), a few files over, divides the very same call by getResources().getDisplayMetrics().density. On iOS the same events carry locationInView: results, which are already points.

Suggested fix

Divide by the display density in makeClickEventData(), the way pointForCoordinate() already does. PR follows.

Ngôn ngữ chính
TypeScript
Star
16k
Fork
5k
Merge trung bình
17 giờ 45 phút
Pull request đã merge (30 ngày)
2

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của react-native-maps/react-native-maps

Tất cả issue của react-native-maps/react-native-maps

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.