Android : Dragging markers in google map Android

on Monday, July 7, 2014


I have a small problem in my application where I'm able to drag marker to any position on the visible map.I referred to this answer on stackoverflow where I can animate the map on marker drag.but even if I don't drop the marker on map it gets dropped by itself.


here's my code to make it more clear



@Override
public void onMarkerDrag(final Marker marker)
{
final View view = getFragmentManager().findFragmentById(R.id.map).getView();
if(view.getViewTreeObserver().isAlive())
{
view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
{

@Override
public void onGlobalLayout()
{
view.getViewTreeObserver().removeGlobalOnLayoutListener(this);

mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder()
.target(marker.getPosition()).zoom(13).build()));

}
});
}


}
};

0 comments:

Post a Comment