xitingTick / osmdroid

Automatically exported from code.google.com/p/osmdroid
0 stars 0 forks source link

Projection.fromPixels() returns wrong lat/long when map is rotated #494

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Display a map, 
2. touch screen and in ontouch event get the screen xy and convert to lat/lon 
via the mapview's projection fromPixels().
3. Rotate that map by some amount (via calling the mapview's 
setMapOrientation() function)
4. Touch again (at same location 0n the rotated map) and convert the xy to 
lat/lon, and note the lat/lon returned is not correct.

What is the expected output? What do you see instead?
Expected output would be the same lat/lon returned for touching the same 
location on a map, regardless of map rotation. What I see is the lat/lon 
returned on the rotated map is (unsure correct terms) arc-shifted by the amount 
of rotation (ie from center point, if rotated 25 degrees, draw a radius to 
original point from center, then draw a line of same radius, 25 degrees to the 
rotation direction, and that is the lat/lon returned).

What version of the product are you using? On what operating system?
osmdroid 4.0, android  4.2.1

Please provide any additional information below.

Original issue reported on code.google.com by nathan.t...@gmail.com on 12 Nov 2013 at 8:51

GoogleCodeExporter commented 8 years ago
To duplicate:
Take the stock OpenStreetMapViewer project and do the following:

MapActivity.java - add 
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
        Log.d("mapactivity", "touchevent");
        Log.d("mapactivity", "Map x/y" + event.getX() + " / " + event.getY());
        MapFragment mapFragment = (MapFragment) this.getSupportFragmentManager().findFragmentById(R.id.map_container);
        if (mapFragment != null) {
            GeoPoint p = mapFragment.toLatLon(event.getX(), event.getY());
            Log.d("mapactivity", "Lat/lon - "  + p.getLatitude() + p.getLongitude());

        }
        return super.onTouchEvent(event);
    }
MapFragment.java, add:
    public GeoPoint toLatLon(float x, float y) {
        return (GeoPoint) mMapView.getProjection().fromPixels(x, y);
    }

    public Point fromLatLon(GeoPoint p) {
        return mMapView.getProjection().toMapPixels(p, null);
    }

Then launch the app. 
Zoom to continental US, touch "Washington DC"
Get a Logcat saying "11-13 12:43:19.171: D/mapactivity(24255): Lat/lon - 
36.244273 -77.124023"
Overflow menu, and enable rotation.
Rotate map ~45 degrees
Tap Washington DC again, logcat says "11-13 12:44:35.581: D/mapactivity(24255): 
Lat/lon - 34.597041-80.112304"
Lat/lon returned from the projection functions doesn't correct for the rotation.

(Sorry that I don't quite have the math/time on hand to dig into what is needed 
to correct this and offer a patch)

Original comment by nathan.t...@gmail.com on 13 Nov 2013 at 5:46

GoogleCodeExporter commented 8 years ago
Updates in 499 may fix this issue once complete.

Original comment by kurtzm...@gmail.com on 10 Dec 2013 at 9:44

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Fixed in Github.

Original comment by kurtzm...@gmail.com on 16 Apr 2014 at 10:28