Reputation: 2320
When I drag the marker in Google Map, I want to update the marker location in realtime and show it in text up the marker.
Now I can just update marker location when end the dragging by implement void onMarkerDragEnd(Marker marker)
, but can't update the location when I am dragging the marker in map.
So how can I update or know marker location when I am dragging it in map?
Upvotes: 1
Views: 1652
Reputation: 14810
You can use onMarkerDrag() for that..See the below given example..
marker=Mmap.addMarker(new MarkerOptions().position(currentpos)
.title("Draggable Marker")
.snippet("Long press and move the marker if needed.")
.draggable(true)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.mark_start)));
Mmap.setOnMarkerDragListener(new OnMarkerDragListener() {
@Override
public void onMarkerDrag(Marker arg0) {
// TODO Auto-generated method stub
Log.d("Marker", "Dragging");
LatLng markerLocation = marker.getPosition();
Log.d("MarkerPosition", markerLocation.toString());
}
@Override
public void onMarkerDragEnd(Marker arg0) {
// TODO Auto-generated method stub
LatLng markerLocation = marker.getPosition();
Toast.makeText(MainActivity.this, markerLocation.toString(), Toast.LENGTH_LONG).show();
Log.d("Marker", "finished");
}
@Override
public void onMarkerDragStart(Marker arg0) {
// TODO Auto-generated method stub
Log.d("Marker", "Started");
}
});
Upvotes: 2