mapbox / mapbox-gl-native

Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL
https://mapbox.com/mobile
Other
4.37k stars 1.33k forks source link

[android]getMetersPerPixelAtLatitude in DP #16587

Open IlyaChizhanov opened 3 years ago

IlyaChizhanov commented 3 years ago

I checked it. It is really in DP.

Platform: Android Mapbox SDK version: 9.5.0

val countPx = 100f
val pointA: LatLng = mapboxMap.projection.fromScreenLocation(PointF(0f, 0f))
val pointB: LatLng = mapboxMap.projection.fromScreenLocation(PointF(countPx, 0f))
val metersInPixel = mapboxMap.projection.getMetersPerPixelAtLatitude(radiusPoint.latitude)

val distance = pointA.distanceTo(pointB)
val distanceOnScreen = metersInPixel * countPx
val distanceOnScreenInDp = metersInPixel * context.pxToDp(countPx)

assertEquals(distance, distanceOnScreen) // assert
assertEquals(distance, distanceOnScreenInDp) // good
oseiskar commented 3 years ago

This is a semi-recent regression. The value was correct (in pixels, not dp) in Mapbox 8.0.0