package org.osmdroid.samplefragments;

import android.content.Context;
import android.location.Location;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

import org.osmdroid.api.IGeoPoint;
import org.osmdroid.api.IMapController;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.overlay.ItemizedIconOverlay;
import org.osmdroid.views.overlay.ItemizedOverlayWithFocus;
import org.osmdroid.views.overlay.MinimapOverlay;
import org.osmdroid.views.overlay.OverlayItem;
import org.osmdroid.views.overlay.gestures.RotationGestureOverlay;
import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider;
import org.osmdroid.views.overlay.mylocation.IMyLocationConsumer;
import org.osmdroid.views.overlay.mylocation.IMyLocationProvider;
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay;

import java.util.ArrayList;

/**
 * @author Tyrone Tudehope
 */
public class SampleAnimatedZoomToLocation extends BaseSampleFragment {

  public static final String TITLE = "Animated Zoom to Location";

  private ItemizedOverlayWithFocus<OverlayItem> mMyLocationOverlay;
  private RotationGestureOverlay mRotationGestureOverlay;

  @Override
  public String getSampleTitle() {
    return TITLE;
  }

  @Override
  protected void addOverlays() {
    super.addOverlays();

    final Context context = getActivity();

    new GpsMyLocationProvider(context).startLocationProvider(new IMyLocationConsumer() {
      @Override
      public void onLocationChanged(Location location, IMyLocationProvider source) {
        if(mMyLocationOverlay == null) {
          final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
          items.add(new OverlayItem("Me", "My Location",
            new GeoPoint(location)));

          mMyLocationOverlay = new ItemizedOverlayWithFocus<OverlayItem>(items,
            new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
              @Override
              public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
                IMapController mapController = mMapView.getController();
                mapController.setCenter(item.getPoint());
                mapController.zoomTo(mMapView.getMaxZoomLevel());
                return true;
              }

              @Override
              public boolean onItemLongPress(final int index, final OverlayItem item) {
                return false;
              }
            }, mResourceProxy);

          mMyLocationOverlay.setFocusItemsOnTap(true);
          mMyLocationOverlay.setFocusedItem(0);

          mMapView.getOverlays().add(mMyLocationOverlay);

          mMapView.getController().setZoom(10);
          IGeoPoint geoPoint = mMyLocationOverlay.getFocusedItem().getPoint();
          mMapView.getController().animateTo(geoPoint);
        }
      }
    });

    mRotationGestureOverlay = new RotationGestureOverlay(context, mMapView);
    mRotationGestureOverlay.setEnabled(false);
    mMapView.getOverlays().add(mRotationGestureOverlay);

    MinimapOverlay miniMapOverlay = new MinimapOverlay(context,
      mMapView.getTileRequestCompleteHandler());
    mMapView.getOverlays().add(miniMapOverlay);
  }

}

@@ -101,153 +101,8 @@
 ion;
-%0Aimport android.os.Bundle;%0Aimport android.view.Menu;%0Aimport android.view.MenuInflater;%0Aimport android.view.MenuItem;%0Aimport android.widget.Toast;
 %0A%0Aim
@@ -691,75 +691,8 @@
 der;
-%0Aimport org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay;
 %0A%0Aim
@@ -1017,16 +1017,236 @@
 Overlay;
+%0A  private GpsMyLocationProvider mGpsMyLocationProvider;%0A%0A  @Override%0A  public void onPause() %7B%0A    super.onPause();%0A    if(mGpsMyLocationProvider != null) %7B%0A      mGpsMyLocationProvider.stopLocationProvider();%0A    %7D%0A  %7D
 %0A%0A  @Ove
@@ -1423,20 +1423,44 @@
 vity();%0A
-%0A
+ 
    
+mGpsMyLocationProvider =
  new Gps
@@ -1486,16 +1486,44 @@
 context)
+;%0A    mGpsMyLocationProvider
 .startLo
@@ -1662,24 +1662,79 @@
 r source) %7B%0A
+        mGpsMyLocationProvider.stopLocationProvider();%0A
         if(m

Remove location updates after location found