I have an Android application that showing maps using OSMDroid.
I want to get the projection pixels of a GeoPoint on the screen, not on the tiles.
Consider the following piece of code:
Projection projection = getProjection();
GeoPoint geoPoint1 = (GeoPoint)projection.fromPixels(0, 0);
Point pixelsPoint = new Point();
projection.toPixels(geoPoint1, pixelsPoint);
GeoPoint geoPoint2 = (GeoPoint)projection.fromPixels(pixelsPoint.x, pixelsPoint.y);
I would like geoPoint1 to be equal to geoPoint2. Instead, I get 2 totally different `GeoPoint’.
In my opininion, the problem is in this line:
projection.toPixels(geoPoint1, pixelsPoint);
The out variable pixelsPoint get filled with values much higher than the screen dimensions (I get 10,000+ for the x and y) and I suspect that this are the pixels on the tile, rather than the screen pixels.
How can I get from GeoPoint to screen pixels back and forth?
You need to compensate for the top left offset, these methods should work: