1

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()));

                    }
                });
            }


        }
    };
Community
  • 1
  • 1
Pankaj
  • 2,115
  • 2
  • 19
  • 39
  • I don't understand. What exactly do you want to achieve? – SeahawksRdaBest Jul 08 '14 at 05:59
  • If I drag the marker over the google map,and while dragging if I reach at the corner of the screen ,google map camera should animate to make marker at centre again,example when you drag the icon from home Screen to create shortcut or uninstall your home screen swipes itself @SeahawksRdaBest – Pankaj Jul 08 '14 at 06:08

1 Answers1

4

try below code for drag marker:-

    map. addMarker(new MarkerOptions().position(new LatLng(lat, lng)).draggable(true));

and below method for get lat nd lng :-

    map.setOnMarkerDragListener(new OnMarkerDragListener() 
    {
        @Override
        public void onMarkerDragStart(Marker marker) 
        {
            // TODO Auto-generated method stub
        }

        @Override
        public void onMarkerDragEnd(Marker marker) 
        {
            // TODO Auto-generated method stub
            lat     = marker.getPosition().latitude;
            lng     = marker.getPosition().longitude;
        }

        @Override
        public void onMarkerDrag(Marker marker)
        {
            // TODO Auto-generated method stub
        }
     });

read below this document :-

https://developers.google.com/maps/documentation/android/marker

duggu
  • 37,851
  • 12
  • 116
  • 113
  • I think you misunderstood my question,what I want is to animate map onMarkerDrag, neither on dragStart nor on DragEnd – Pankaj Jul 08 '14 at 04:18