handling touch events in MapView

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

handling touch events in MapView

Postby ptucker » Wed Jun 10, 2009 5:09 pm

I have created a MapActivity containing a MapView. Drag and zoom work fine, and I've successfully added an ItemizedOverlay that displays and updates properly. Right now I can add OverlayItems to the map center via a button, but I would like to add functionality allowing the user to issue a long click to add an OverlayItem to the map at the selected location.

My first attempt was to use setLongClickable(true) and setOnLongClickListener, but that doesn't provide the click location. The only param it receives it the View object, but I couldn't find any way to determine the location of the click event.

My second attempt was to use setOnTouchListener. This seems completely broken to me. If I return true (ie, consume event) I continue getting all touch events, but drag and zoom of the MapView do not work. That seems like expected behavior. If I return false (ie, do not consume the event) the map view continues to work correctly. My listener receives ONLY the first touch event. Stepping through in debug, it looks like MapView.mOnTouchListener gets set to something like ZoomListener (that's not the exact name, but it's close to that) and then to null shortly after my listener is invoked. Is there another preferred way of handling touch events in MapView?

I was able to work around it by extending MapView and overriding onTouchEvent(). I found that if I used MapView.setOnTouchListener() directly, MapView itself would call setOnTouchListener(), discarding my listener and replacing it with a zoom listener.
ptucker
Freshman
Freshman
 
Posts: 4
Joined: Wed Jun 10, 2009 5:05 pm

Top

Re: handling touch events in MapView

Postby tanran » Sat Jul 18, 2009 8:38 am

ptucker wrote:I have created a MapActivity containing a MapView. Drag and zoom work fine, and I've successfully added an ItemizedOverlay that displays and updates properly. Right now I can add OverlayItems to the map center via a button, but I would like to add functionality allowing the user to issue a long click to add an OverlayItem to the map at the selected location.

My first attempt was to use setLongClickable(true) and setOnLongClickListener, but that doesn't provide the click location. The only param it receives it the View object, but I couldn't find any way to determine the location of the click event.

My second attempt was to use setOnTouchListener. This seems completely broken to me. If I return true (ie, consume event) I continue getting all touch events, but drag and zoom of the MapView do not work. That seems like expected behavior. If I return false (ie, do not consume the event) the map view continues to work correctly. My listener receives ONLY the first touch event. Stepping through in debug, it looks like MapView.mOnTouchListener gets set to something like ZoomListener (that's not the exact name, but it's close to that) and then to null shortly after my listener is invoked. Is there another preferred way of handling touch events in MapView?

I was able to work around it by extending MapView and overriding onTouchEvent(). I found that if I used MapView.setOnTouchListener() directly, MapView itself would call setOnTouchListener(), discarding my listener and replacing it with a zoom listener.

u want to add an overlayitem to the selected point.
u should initialize an itemizedOverlay, the u can overide it's method:
public boolean onTap(GeoPoint point, MapView mapView){
//...
}

u can try it.
tanran
Junior Developer
Junior Developer
 
Posts: 12
Joined: Wed Apr 22, 2009 2:16 am

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 2 guests