OpenStreetMap Forum

The Free Wiki World Map

You are not logged in.

#1 2012-06-05 10:01:37

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 ... hmm

How can I do that ?

Thanks.

Offline

#2 2012-06-06 18:55:06

Tordanik
Super Senior Member
From: Germany
Registered: 2008-06-17
Posts: 1,548
Website

Re: Get geographic coordinates from pixels

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.

Offline

#3 2012-06-12 14:45:42

Re: Get geographic coordinates from pixels

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);

Offline

Board footer

Powered by FluxBB 1.4.8
Hosting sponsored by Oxilion