Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • User position marker Rotation (Animation) as in Uber app

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 487
    Answer it

    Hello, 
    I was reading through this post http://findnerd.com/list/view/Problem-in-Google-map-rotation-in-Android/23827/
    and was searching for a solution of rotation issue. I want to implement same as in uber app. https://drive.google.com/open?id=1J3jLEJb7_tj6fBOFpaXODYE1fMCBy_TJ

    If anyone have solved this then please reply here.

    I am using following code for rotation and animation: 

    public void animateMarker(final Marker marker, final LatLng toPosition) {

        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();

      Projection proj = mGoogleMap.getProjection();

      Point startPoint = proj.toScreenLocation(carMarker.getPosition());

      final LatLng startLatLng = proj.fromScreenLocation(startPoint);

        final long duration = 800;//500

        final Interpolator interpolator = new LinearInterpolator();

        handler.post(new Runnable() {
            @Override
            public void run() {

                long elapsed = SystemClock.uptimeMillis() - start;
                float t = interpolator.getInterpolation((float) elapsed / duration);

                double currlat = t * toPosition.latitude + (1 - t) * startLatLng.latitude;
                double currlng = t * toPosition.longitude + (1 - t) * startLatLng.longitude;

                LatLng latlng= new LatLng (currlat, currlng);

                marker.setPosition(latlng);

                if (t < 0.7) {
                    // Post again 16ms later.
                    handler.postDelayed(this, 16);
                } else {

                }
            }
        });
    }

    private void rotateMarker(final Marker marker, float fromRotation, final float toRotation) {

        if (!isMarkerRotating) {
            final Handler handler = new Handler();
            final long start = SystemClock.uptimeMillis();
            final float startRotation = fromRotation;
            final long duration = 1000;

            final Interpolator interpolator = new LinearInterpolator();

            handler.post(new Runnable() {
                @Override
                public void run() {
                    isMarkerRotating = true;

                    long elapsed = SystemClock.uptimeMillis() - start;
                    float t = interpolator.getInterpolation((float) elapsed / duration);

                    float rot = t * toRotation + (1 - t) * startRotation;

                    marker.setRotation(-rot > 180 ? rot / 2 : rot);

                    if (t < 1.0) {
                        // Post again 16ms later.
                        handler.postDelayed(this, 16);
                    } else {
                        isMarkerRotating = false;
                    }
                }
            });
        }
    }

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: