Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the Latitude and Longitude of a position clicked on a maps forge 0.5.1 MapView

I use the maps forge 0.5.1 libraries (api reference) I have followed all the official instructions but I have the following problem :

I have attached an onTouchListener on the

(org.mapsforge.map.android.view.MapView)mapView

but when I try to call the method mapView.getProjection(), I get the error "Cannot resolve the method getProjection(). Even if the method is getting called in many online examples,there is not in the official api reference or in MapView.class. org.mapsforge.map.android.view.MapView

 org.mapsforge.map.android.view.MapView mapView;
 mapView.setOnTouchListener(new View.OnTouchListener(){

        @Override
        public boolean onTouch(View v, MotionEvent ev) {
            int actionType = ev.getAction();
            switch (actionType) {
                case MotionEvent.ACTION_DOWN:

                    return false;

                case MotionEvent.ACTION_UP:
                    mapView.getProjection(); // the error is here

                    return true;
                case MotionEvent.ACTION_MOVE:
                    return false;
            }
            return false;
        }
    });

Is there any alternative way to get the latitude and longitude of the tapped point using mapsforge lib? Am I doing something wrong? If there is no way to get the coordinates after a tap, I thing that the library is missing something very important.

Thank you

like image 820
karvoynistas Avatar asked May 06 '15 15:05

karvoynistas


1 Answers

Use

new MapViewProjection(mapView).fromPixels(double x, double y);

THey reversed the linkage in version 0.4 or so- now instead of getting the projection from a mapview, you pass a mapview to a projection.

like image 76
Gabe Sechan Avatar answered Nov 15 '22 18:11

Gabe Sechan