I set up a marker an set it\'s draggable state to true. But when I call marker.getPosition()
I am always getting the same location, like marker\'s position is n
You should implement OnMarkerDragListener()
in your main activity. And inside the method onMarkerDragEnd()
you can get the position of your marker (by using its ID)
This is an old question but since I had the same problem myself, here's the solution: you need to set the OnMarkerDragListener
for the map instance first (mMap.setOnMarkerDragListener(...)
) for the markers position value to get updated. You don't really need to do anything inside the listener implementation methods (you can use marker.getPosition()
anywhere you like), they just have to exist.
UPDATE
This is also documented now in https://developers.google.com/maps/documentation/android-api/marker#marker_drag_events
You can use an OnMarkerDragListener to listen for drag events on a marker. To set this listener on the map, call GoogleMap.setOnMarkerDragListener. To drag a marker, a user must long press on the marker. When the user takes their finger off the screen, the marker will stay in that position. When a marker is dragged, onMarkerDragStart(Marker) is called initially. While the marker is being dragged, onMarkerDrag(Marker) is called constantly. At the end of the drag onMarkerDragEnd(Marker) is called. You can get the position of the marker at any time by calling Marker.getPosition().