package com.evgenii.walktocircle.WalkMap;

import android.location.Location;

import com.evgenii.walktocircle.Utils.WalkGeo;
import com.evgenii.walktocircle.Utils.WalkLocation;
import com.evgenii.walktocircle.WalkConstants;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

public class DropPin {
    static private Marker mPreviousMarker;

    public void dropPin(Location currentLocation, GoogleMap map) {
        removePreviousMarker();

        Location pinLocation = WalkGeo.randomLocationAtDistanceRange(currentLocation,
                WalkConstants.minCircleDistanceFromCurrentLocationMeters,
                WalkConstants.maxCircleDistanceFromCurrentLocationMeters);

        LatLng latLng = WalkLocation.latLngFromLocation(pinLocation);
        MarkerOptions markerOptions = new MarkerOptions().position(latLng).title("Walk to Circle");
        mPreviousMarker = map.addMarker(markerOptions);
    }

    private void removePreviousMarker() {
        if (mPreviousMarker == null) { return; }
        mPreviousMarker.remove();
    }
}

@@ -55,25 +55,208 @@
 oid.
-location.Location
+graphics.Point;%0Aimport android.location.Location;%0Aimport android.os.Handler;%0Aimport android.os.SystemClock;%0Aimport android.view.animation.Interpolator;%0Aimport android.view.animation.LinearInterpolator
 ;%0A%0Ai
@@ -446,16 +446,63 @@
 gleMap;%0A
+import com.google.android.gms.maps.Projection;%0A
 import c
@@ -1277,16 +1277,61 @@
 tions);%0A
+        animateMarker(mPreviousMarker, map);%0A
     %7D%0A%0A 
@@ -1420,16 +1420,16 @@
 turn; %7D%0A
-
         
@@ -1459,11 +1459,1332 @@
 );%0A    %7D
+%0A%0A    private void animateMarker(final Marker marker, GoogleMap map) %7B%0A        final LatLng target = new LatLng(marker.getPosition().latitude, marker.getPosition().longitude);%0A        Projection projection = map.getProjection();%0A        Point startPoint = projection.toScreenLocation(target);%0A        startPoint.y = 0;%0A        final LatLng startLatLng = projection.fromScreenLocation(startPoint);%0A%0A        final long duration = 400;%0A        final long startTime = SystemClock.uptimeMillis();%0A        final Interpolator interpolator = new LinearInterpolator();%0A        final Handler handler = new Handler();%0A        handler.post(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                long elapsed = SystemClock.uptimeMillis() - startTime;%0A                float t = interpolator.getInterpolation((float) elapsed / duration);%0A                double lng = t * target.longitude + (1 - t) * startLatLng.longitude;%0A                double lat = t * target.latitude + (1 - t) * startLatLng.latitude;%0A                marker.setPosition(new LatLng(lat, lng));%0A                if (t %3C 1.0) %7B%0A                    // Post again 10ms later.%0A                    handler.postDelayed(this, 5);%0A                %7D else %7B%0A                    // animation ended%0A                %7D%0A            %7D%0A        %7D);%0A    %7D
 %0A%7D%0A

Drop a pin