10

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

karvoynistas
  • 1,295
  • 1
  • 14
  • 30

3 Answers3

6

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.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
1

Are you sure you imported the right MapView? There is a Google version of MapView that does not have that function, if you imported that it could be thinking its the wrong class.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • No, I have declared my MapView as org.mapsforge.map.android.view.MapView. – karvoynistas May 21 '15 at 21:28
  • Hmm. I just looked at the docs you pointed to- there's no getProjection function there either. Not sure why you think that function should exist. – Gabe Sechan May 21 '15 at 21:31
  • Older versions of mapsforge like 0.3 or 0.4 contain the getProjection method. The point is, is there anyway to get the coordinates of the clicked point? It is strange that the older versions are more complete than the last. – karvoynistas May 21 '15 at 21:34
  • 1
    You should try to be much clearer with your problems. As written, your problem looks like a compilation problem, the answer to which is "they removed the function, you can't use that". What you want is "How do I get the Latitude and Longitude of a position clicked on a mapsforge MapView", which is a totally legitimate but totally different question. And likely would get more people to view then yet another compilation problem question. – Gabe Sechan May 21 '15 at 21:44
1

You can make use of the onTap event from TileRendererLayer, so that you need not to handle the ``View.onTouch event, which is more difficult in identifying a single tap / click.

// tile renderer layer using internal render theme
MapDataStore mapDataStore = new MapFile(filename);
TileRendererLayer tileRendererLayer = 
        new TileRendererLayer(tileCache,
                              mapDataStore,
                              this.mapView.getModel().mapViewPosition,
                              AndroidGraphicFactory.INSTANCE) {
    @Override
    public boolean onTap(LatLong tapLatLong, Point layerXY, Point tapXY) {
        ShowTapLocation(tapLatLong);
        return true;
    }
};
petey
  • 16,914
  • 6
  • 65
  • 97
Alivina
  • 11
  • 2