Get geographic coordinates from pixels

Hello,

I use an extended class of MapView and I want to modify the interactions with the user.


public boolean onTouchEvent(MotionEvent motionEvent) {

	float x = motionEvent.getX();
	float y = motionEvent.getY();
	byte zoomLevel = this.getMapPosition().getZoomLevel();
        return true;
}

For example I get X : 804.3716, Y : 344.0, Zoom : 13
And now I want to get the geographic coordinates (the mercator point). I try to use the class MercatorProjection in org.mapsforge.core but It seems that it’s not the right solution … :confused:

How can I do that ?

Thanks.

What Framework/Library are you using? There are several available for OSM, so it’s not clear (at least to me) which one we are talking about.

Hello, I use Mapsforge, but I found the solution.
You may use the class Projection like this :


long x = motionEvent.getX();
long y = motionEvent.getY();
byte zoomLevel = this.getMapPosition().getZoomLevel();
	
Projection p = this.getProjection();
GeoPoint g = p.fromPixels((int)x,(int)y);
double latitude = g.getLatitude();
double longitude = g.getLongitude();
		
Log.v("Projection", "Coordonnées : " + latitude + " " + longitude);