liangzi7 / osmdroid

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

Where the origin of the pixel coordinate? #484

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.I'm doing distance measure tool。
2.when i using mapView.getProjection().toPixels。I found the output pixel 
coordinates are wrong
3.

What is the expected output? What do you see instead?

GeoPoint point = new GeoPoint((int) (39.90923 * 1E6), (int) (116.397428 * 
1E6)); mMapController.setCenter(point);
mMapController.setZoom(12); 
Point pntC = mapView.getProjection().toPixels(mapView.getMapCenter(),null);

osmdroid
pin is Point(5295, -1980)

google map api
pnt is Point(0, 0)

What version of the product are you using? On what operating system?

Please provide any additional information below.

Original issue reported on code.google.com by hanhe...@gmail.com on 12 Oct 2013 at 10:33

GoogleCodeExporter commented 9 years ago
How can I get the coordinates ,that origin is the upper left corner of the 
mapview

Original comment by hanhe...@gmail.com on 12 Oct 2013 at 10:47

GoogleCodeExporter commented 9 years ago
I tested this.
        GeoPoint point = new GeoPoint((int) (39.90923 * 1E6), (int) (116.397428 * 1E6));
        Point pntC = mapView.getProjection().toPixels(point,null);

        IGeoPoint point2 = mapView.getProjection().fromPixels(pntC.x, pntC.y);

point2 is (84254150,230097656)

point point2 not equal

Original comment by hanhe...@gmail.com on 14 Oct 2013 at 3:11

GoogleCodeExporter commented 9 years ago
I changed toPixels like this :
        @Override
        public Point toPixels(final IGeoPoint in, final Point out) {
            Point pnt = toMapPixels(in, out);
            final Rect screenRect = getIntrinsicScreenRect();
            pnt.x = pnt.x - screenRect.left ;
            pnt.y = pnt.y - screenRect.top ;
            return pnt;
        }

It worked!i

Original comment by hanhe...@gmail.com on 14 Oct 2013 at 3:14