I am trying to configure an onDrag Listener for a google map fragment, but cannot trigger a drag event. Since the map does not support direct drag and drop events, I am trying to implement a drag and drop listener for the view. I know about the onMarkerDrag event, but that doesn't do me any good, since I'm not trying to move markers.
The reason for intercepting card drag events is twofold:
First, to determine if the user has launched a map. If they havenโt, I like to keep their location on the screen and animate their location if it is not on the map. If they launched a map, I assume that they know what they want to see, and force a place on the screen. (this is similar to what should be included in the API)
The second reason for capture is to allow users to draw lines and polygons on the map. I can do this using the onTap events (adding points), but I would also like to let them undo it.
My code is as follows:
mainActivity:
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); setUpMapIfNeeded(); mMapView = findViewById(R.id.map); myMapDragListener = new MapDragListener(); mMapView.setOnDragListener(myMapDragListener);
Listener:
public class MapDragListener implements OnDragListener { /** * */ public MapDragListener() { super(); say.logCat("MapDragListener: I'm ALIVE!!!!"); } private AkamaiAnnounce say = new AkamaiAnnounce(); private boolean inDrag; private boolean hasPanned=false; @Override public boolean onDrag(View v, DragEvent event) { say.logCat("MapDragListener.onDrag: " + event.toString()); //String dotTAG = (String) getTag(); if (event.getLocalState() != this) { return false; } boolean myResult = true; int action = event.getAction(); float x = event.getX(); float y = event.getY(); switch (action) { case DragEvent.ACTION_DRAG_STARTED: inDrag = true; break; case DragEvent.ACTION_DRAG_LOCATION: break; case DragEvent.ACTION_DRAG_ENTERED: break; case DragEvent.ACTION_DRAG_EXITED: break; case DragEvent.ACTION_DROP: myResult = false; break; case DragEvent.ACTION_DRAG_ENDED: inDrag = false; // change color of original dot back hasPanned=true; break; default: myResult = false; break; } return false; //return myResult; } public boolean hasPanned() { return hasPanned; } public void setHasPanned(boolean hasPanned) { this.hasPanned = hasPanned; } }
The map works great. The listener fires, but my onDrag event never fires. Any ideas?
android google-maps google-maps-android-api-2 drag
Tim Jun 20 '13 at 20:27 2013-06-20 20:27
source share