I am using google maps API and I have some code that tries to capture the position of the center of the map after the user has dragged it.
MapView mv = ...;
mv.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
GeoPoint pt = mv.getMapCenter();
//do something with the point
return A;
}
return B;
}
});
Now my problem is with the return values:
- if B is false, the map gets dragged but I only see the
ACTION_DOWNevent andACTION_UPis never triggered – which I understand - if B is true, I receive the
ACTION_UPevent, but the map is not dragged - it seems that whether A is true or false does not make a difference
What I want is to receive the ACTION_UP event AND to have the map dragged.
What am I missing here?
Here’s one solution: Instead of using the default MapView, use a custom MapView which has a GestureDetector, basically, this lets you create a custom event listener for your map which helps you avoid the issue of messing up the dragging etc. and moreover gives you are vast number of interaction options compared to the default MapView. A couple of months ago I’d faced a similar problem and so I decided to implement the solution I just mentioned. Here’s the code for the custom MapView called TapControlledMapView and the code for the interface for the custom listener is provided at the bottom : http://pastebin.com/kUrm9zFg.
So to implement the listener, all you need to do is use the following code in your mapactivity class (Oh and in case you didn’t know this, you have to declare the following in your MapActivity layout XML file since you are using a custom MapView:
and use the following code in your MapActivity class.
Let me know how it goes.