Hi i create Fragment when i add MapEventsReceiver to detect shape type (Rectangle, Polygon, Line, Marker etc) in order to detect with shape are clicked. But i have problem with Marker, i can't detect when marker is clicked. I add Toast message when i clicked on map (MapEventsReceiver method longPressHelper()) and when i clicked on all shapes it's work perfect but not in Marker (it's run onLongPress method from marker class). It's possible to add Marker listener to longPressHelper from MapEventReceiver ( I want to detect Marker clicked in longPressHelper)?
The problem with Marker
is that it actually handles the long press by itself and prevents it from propagating.
If you inspect the source code of Marker
@Override public boolean onLongPress(final MotionEvent event, final MapView mapView) {
boolean touched = hitTest(event, mapView);
if (touched){
if (mDraggable){
//starts dragging mode:
mIsDragged = true;
closeInfoWindow();
if (mOnMarkerDragListener != null)
mOnMarkerDragListener.onMarkerDragStart(this);
moveToEventPosition(event, mapView);
}
}
return touched;
}
You can see that when you longpress the marker the method returns true and that means, that touch event wont be propagated to other overlays nor to MapView
.
However, if you don't need the drag functionality of a marker, you could extend the Marker
class yourself and override the behaviour:
@Override public boolean onLongPress(final MotionEvent event, final MapView mapView) {
return false;
}
Now, if you use your derived class, the long press should be propagated to the MapView
.