I'm having issues in creating event handler that will be triggered while user moves the map around. There is a OnCameraChangeListener
, but it is triggered after map moving stops.
I have created SurfaceView
over Maps, and now I have no idea how to handle onScroll
event from OnGestureListener
.
Here is the sample code:
SurfaceView sv = new SView();
sv.setZOrderOnTop(true);
mapView.addView(sv);
...
public class SView extends SurfaceView implements Runnable, android.view.GestureDetector.OnGestureListener {
...
@Override
public boolean onTouchEvent(MotionEvent event) {
//this worked in Overlay in Maps API v1
if(gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
...
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
Log.i("test","onScroll");
return false;
}
...
}
If I set return true
in onTouchEvent
, onScroll
is called but than I can't move the Map (which is obvious, the event is consumed), and I don't know how to dispatch event down to Map object.
Anyone knows how to update SurfaceView
while Map is moved?
From: Android ListView: overriding causes scrolling do not executed
Other possible helpful links:
I have implemented some other solution to solve this problem. What I did - is I placed my GoogleMap inside custom RelativeLayout. After that
onInterceptTouchEvent
callback works like a charm and underlying map receives touch events as expectedhere is my xml:
And custom relative layout: