问题
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