How to handle long press on a map, using OSMDroid / OSMBonusPack in Android?

限于喜欢 提交于 2019-12-12 15:13:37

问题


I am trying to create a simple application with maps, on Android. I am using OSMDroid's MapView to render the basic OpenStreet Map mapview.

I have a custom MapActivity that implements the MapEventsReceiver interface (from OSMBonusPack). In my activity's onCreate(), I create a MapEventsOverlay, I add it to the mapView.

The problem is, longPressHelper() and singleTapUpHelper() are never called. See my code below.

public abstract class CustomMap extends BaseActivity implements MapEventsReceiver{
//variable declarations follow
private MapView mMapView;

@Override
protected void onCreate(Bundle icicle) {
super.onCreate(load);
setContentView(R.layout.activity_map_main_screen);

mMapView = (MapView) findViewById(R.id.mapmainscreen);
mMapView.setBuiltInZoomControls(true);
mMapView.setClickable(true);

MapEventsOverlay evOverlay = new MapEventsOverlay(this, this);
mMapView.getOverlays.add(evOverlay);
mMapView.invalidate();

//tile source / tile provider are set by another method elsewhere

//somewhere in my code (same class file) I also have this:

@Override
public boolean longPressHelper(IGeoPoint arg0) {
Log.d(TAG, "longPressHelper was called");//this is never called
return true;
}

@Override
public boolean singleTapUpHelper(IGeoPoint arg0) {
Log.d(TAG, "singleTapUpHelper was called");//this is never called
return true;
}
}      
}

Please note that I have tried the suggested solution here OSMDroid: Adding a marker when user taps on map

Any help is much appreciated.


回答1:


The code you provided is correct. So the issue is somewhere else...

Could you specify versions used: Android SDK, osmdroid, and OSMBonusPack?

Maybe something in the layout? You can check by comparing with OSMBonusPackTuto activity_main.xml layout.



来源:https://stackoverflow.com/questions/22804650/how-to-handle-long-press-on-a-map-using-osmdroid-osmbonuspack-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!