0

How can I drag a marker on the map? How to handle it in onTouchEvent()?

I had written one code that actually drags. But it feels like the map is moving instead of the marker. That code is written below:

public boolean onTouchEvent(MotionEvent event, MapView mapView) { /*Action to be taken on ACTION_UP(value=1) and ACTION_DOWN(value=0)*/ if(event.getAction() == 0 || event.getAction() == 1){ mapView.displayZoomControls(true); } /*Action to be taken on ACTION_MOVE(value=2)*/ if(event.getAction() == 2){ for(int i = 0; i < mOverlays.size() ; i++){ mOverlays.remove(i); } GeoPoint point = mapView.getProjection().fromPixels((int) event.getX(),(int) event.getY()); OverlayItem overlayItem = new OverlayItem(point, "", ""); addOverlay(overlayItem); mapView.getController().setCenter(point); } return true; } 

Is there any solution for this?

1 Answer 1

2

Of course the map is moving. You are telling the map to move via setCenter().

Here is a sample project showing drag and drop of OverlayItems.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.