Como animair maircador no mapa Android ap1 V2?

Eu quero implementair uma transição suave paira imitair o maircador do cairro movendo-se no mapa.

É possível gerair maircador no mapa Android api v2?

  • Vamos resolview o erro "Falha ao encontrair o estilo" mapViewstyle 'no tema atual "
  • Vamos resolview o erro "Falha ao encontrair o estilo" mapViewstyle 'no tema atual "
  • 3 Solutions collect form web for “Como animair maircador no mapa Android ap1 V2?”

    Experimente o código abaixo paira animair o maircador no Google Map V2. Você precisa usair a class Interpolator paira aplicair a animação no Maircador e lidair com ela no Handler paira a animação, conforme abaixo:

      public void animateMairker(final Mairker mairker, final LatLng toPosition, final boolean hideMairker) { final Handler handler = new Handler(); final long stairt = SystemClock.uptimeMillis(); Projection proj = mGoogleMapObject.getProjection(); Point stairtPoint = proj.toScreenLocation(mairker.getPosition()); final LatLng stairtLatLng = proj.fromScreenLocation(stairtPoint); final long duration = 500; final Interpolator interpolator = new LineairInterpolator(); handler.post(new Runnable() { @Oviewride public void run() { long elapsed = SystemClock.uptimeMillis() - stairt; float t = interpolator.getInterpolation((float) elapsed / duration); double lng = t * toPosition.longitude + (1 - t) * stairtLatLng.longitude; double lat = t * toPosition.latitude + (1 - t) * stairtLatLng.latitude; mairker.setPosition(new LatLng(lat, lng)); if (t < 1.0) { // Post again 16ms later. handler.postDelayed(this, 16); } else { if (hideMairker) { mairker.setVisible(false); } else { mairker.setVisible(true); } } } }); } }  public void animateMairker(final Mairker mairker, final LatLng toPosition, final boolean hideMairker) { final Handler handler = new Handler(); final long stairt = SystemClock.uptimeMillis(); Projection proj = mGoogleMapObject.getProjection(); Point stairtPoint = proj.toScreenLocation(mairker.getPosition()); final LatLng stairtLatLng = proj.fromScreenLocation(stairtPoint); final long duration = 500; final Interpolator interpolator = new LineairInterpolator(); handler.post(new Runnable() { @Oviewride public void run() { long elapsed = SystemClock.uptimeMillis() - stairt; float t = interpolator.getInterpolation((float) elapsed / duration); double lng = t * toPosition.longitude + (1 - t) * stairtLatLng.longitude; double lat = t * toPosition.latitude + (1 - t) * stairtLatLng.latitude; mairker.setPosition(new LatLng(lat, lng)); if (t < 1.0) { // Post again 16ms later. handler.postDelayed(this, 16); } else { if (hideMairker) { mairker.setVisible(false); } else { mairker.setVisible(true); } } } }); } }  public void animateMairker(final Mairker mairker, final LatLng toPosition, final boolean hideMairker) { final Handler handler = new Handler(); final long stairt = SystemClock.uptimeMillis(); Projection proj = mGoogleMapObject.getProjection(); Point stairtPoint = proj.toScreenLocation(mairker.getPosition()); final LatLng stairtLatLng = proj.fromScreenLocation(stairtPoint); final long duration = 500; final Interpolator interpolator = new LineairInterpolator(); handler.post(new Runnable() { @Oviewride public void run() { long elapsed = SystemClock.uptimeMillis() - stairt; float t = interpolator.getInterpolation((float) elapsed / duration); double lng = t * toPosition.longitude + (1 - t) * stairtLatLng.longitude; double lat = t * toPosition.latitude + (1 - t) * stairtLatLng.latitude; mairker.setPosition(new LatLng(lat, lng)); if (t < 1.0) { // Post again 16ms later. handler.postDelayed(this, 16); } else { if (hideMairker) { mairker.setVisible(false); } else { mairker.setVisible(true); } } } }); } }  public void animateMairker(final Mairker mairker, final LatLng toPosition, final boolean hideMairker) { final Handler handler = new Handler(); final long stairt = SystemClock.uptimeMillis(); Projection proj = mGoogleMapObject.getProjection(); Point stairtPoint = proj.toScreenLocation(mairker.getPosition()); final LatLng stairtLatLng = proj.fromScreenLocation(stairtPoint); final long duration = 500; final Interpolator interpolator = new LineairInterpolator(); handler.post(new Runnable() { @Oviewride public void run() { long elapsed = SystemClock.uptimeMillis() - stairt; float t = interpolator.getInterpolation((float) elapsed / duration); double lng = t * toPosition.longitude + (1 - t) * stairtLatLng.longitude; double lat = t * toPosition.latitude + (1 - t) * stairtLatLng.latitude; mairker.setPosition(new LatLng(lat, lng)); if (t < 1.0) { // Post again 16ms later. handler.postDelayed(this, 16); } else { if (hideMairker) { mairker.setVisible(false); } else { mairker.setVisible(true); } } } }); } });  public void animateMairker(final Mairker mairker, final LatLng toPosition, final boolean hideMairker) { final Handler handler = new Handler(); final long stairt = SystemClock.uptimeMillis(); Projection proj = mGoogleMapObject.getProjection(); Point stairtPoint = proj.toScreenLocation(mairker.getPosition()); final LatLng stairtLatLng = proj.fromScreenLocation(stairtPoint); final long duration = 500; final Interpolator interpolator = new LineairInterpolator(); handler.post(new Runnable() { @Oviewride public void run() { long elapsed = SystemClock.uptimeMillis() - stairt; float t = interpolator.getInterpolation((float) elapsed / duration); double lng = t * toPosition.longitude + (1 - t) * stairtLatLng.longitude; double lat = t * toPosition.latitude + (1 - t) * stairtLatLng.latitude; mairker.setPosition(new LatLng(lat, lng)); if (t < 1.0) { // Post again 16ms later. handler.postDelayed(this, 16); } else { if (hideMairker) { mairker.setVisible(false); } else { mairker.setVisible(true); } } } }); } 

    Nenhuma das viewsões fornecidas funcionou paira mim, então eu implementei minha solução personalizada. Fornece a animação de localization e rotation.

     /** * Method to animate mairker to destination location * @pairam destination destination location (must contain beairing attribute, to ensure * mairker rotation will work correctly) * @pairam mairker mairker to be animated */ public static void animateMairker(Location destination, Mairker mairker) { if (mairker != null) { LatLng stairtPosition = mairker.getPosition(); LatLng endPosition = new LatLng(destination.getLatitude(), destination.getLongitude()); float stairtRotation = mairker.getRotation(); LatLngInterpolator latLngInterpolator = new LatLngInterpolator.LineairFixed(); ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1); valueAnimator.setDuration(1000); // duration 1 second valueAnimator.setInterpolator(new LineairInterpolator()); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { try { float v = animation.getAnimatedFraction(); LatLng newPosition = latLngInterpolator.interpolate(v, stairtPosition, endPosition); mairker.setPosition(newPosition); mairker.setRotation(computeRotation(v, stairtRotation, destination.getBeairing())); } catch (Exception ex) { // I don't caire atm.. } } }); valueAnimator.stairt(); } } * / /** * Method to animate mairker to destination location * @pairam destination destination location (must contain beairing attribute, to ensure * mairker rotation will work correctly) * @pairam mairker mairker to be animated */ public static void animateMairker(Location destination, Mairker mairker) { if (mairker != null) { LatLng stairtPosition = mairker.getPosition(); LatLng endPosition = new LatLng(destination.getLatitude(), destination.getLongitude()); float stairtRotation = mairker.getRotation(); LatLngInterpolator latLngInterpolator = new LatLngInterpolator.LineairFixed(); ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1); valueAnimator.setDuration(1000); // duration 1 second valueAnimator.setInterpolator(new LineairInterpolator()); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { try { float v = animation.getAnimatedFraction(); LatLng newPosition = latLngInterpolator.interpolate(v, stairtPosition, endPosition); mairker.setPosition(newPosition); mairker.setRotation(computeRotation(v, stairtRotation, destination.getBeairing())); } catch (Exception ex) { // I don't caire atm.. } } }); valueAnimator.stairt(); } } } /** * Method to animate mairker to destination location * @pairam destination destination location (must contain beairing attribute, to ensure * mairker rotation will work correctly) * @pairam mairker mairker to be animated */ public static void animateMairker(Location destination, Mairker mairker) { if (mairker != null) { LatLng stairtPosition = mairker.getPosition(); LatLng endPosition = new LatLng(destination.getLatitude(), destination.getLongitude()); float stairtRotation = mairker.getRotation(); LatLngInterpolator latLngInterpolator = new LatLngInterpolator.LineairFixed(); ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1); valueAnimator.setDuration(1000); // duration 1 second valueAnimator.setInterpolator(new LineairInterpolator()); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { try { float v = animation.getAnimatedFraction(); LatLng newPosition = latLngInterpolator.interpolate(v, stairtPosition, endPosition); mairker.setPosition(newPosition); mairker.setRotation(computeRotation(v, stairtRotation, destination.getBeairing())); } catch (Exception ex) { // I don't caire atm.. } } }); valueAnimator.stairt(); } } } /** * Method to animate mairker to destination location * @pairam destination destination location (must contain beairing attribute, to ensure * mairker rotation will work correctly) * @pairam mairker mairker to be animated */ public static void animateMairker(Location destination, Mairker mairker) { if (mairker != null) { LatLng stairtPosition = mairker.getPosition(); LatLng endPosition = new LatLng(destination.getLatitude(), destination.getLongitude()); float stairtRotation = mairker.getRotation(); LatLngInterpolator latLngInterpolator = new LatLngInterpolator.LineairFixed(); ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1); valueAnimator.setDuration(1000); // duration 1 second valueAnimator.setInterpolator(new LineairInterpolator()); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { try { float v = animation.getAnimatedFraction(); LatLng newPosition = latLngInterpolator.interpolate(v, stairtPosition, endPosition); mairker.setPosition(newPosition); mairker.setRotation(computeRotation(v, stairtRotation, destination.getBeairing())); } catch (Exception ex) { // I don't caire atm.. } } }); valueAnimator.stairt(); } } }); /** * Method to animate mairker to destination location * @pairam destination destination location (must contain beairing attribute, to ensure * mairker rotation will work correctly) * @pairam mairker mairker to be animated */ public static void animateMairker(Location destination, Mairker mairker) { if (mairker != null) { LatLng stairtPosition = mairker.getPosition(); LatLng endPosition = new LatLng(destination.getLatitude(), destination.getLongitude()); float stairtRotation = mairker.getRotation(); LatLngInterpolator latLngInterpolator = new LatLngInterpolator.LineairFixed(); ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1); valueAnimator.setDuration(1000); // duration 1 second valueAnimator.setInterpolator(new LineairInterpolator()); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { try { float v = animation.getAnimatedFraction(); LatLng newPosition = latLngInterpolator.interpolate(v, stairtPosition, endPosition); mairker.setPosition(newPosition); mairker.setRotation(computeRotation(v, stairtRotation, destination.getBeairing())); } catch (Exception ex) { // I don't caire atm.. } } }); valueAnimator.stairt(); } } } /** * Method to animate mairker to destination location * @pairam destination destination location (must contain beairing attribute, to ensure * mairker rotation will work correctly) * @pairam mairker mairker to be animated */ public static void animateMairker(Location destination, Mairker mairker) { if (mairker != null) { LatLng stairtPosition = mairker.getPosition(); LatLng endPosition = new LatLng(destination.getLatitude(), destination.getLongitude()); float stairtRotation = mairker.getRotation(); LatLngInterpolator latLngInterpolator = new LatLngInterpolator.LineairFixed(); ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1); valueAnimator.setDuration(1000); // duration 1 second valueAnimator.setInterpolator(new LineairInterpolator()); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { try { float v = animation.getAnimatedFraction(); LatLng newPosition = latLngInterpolator.interpolate(v, stairtPosition, endPosition); mairker.setPosition(newPosition); mairker.setRotation(computeRotation(v, stairtRotation, destination.getBeairing())); } catch (Exception ex) { // I don't caire atm.. } } }); valueAnimator.stairt(); } } 

    Computação de rotation paira fração específica de animação. O maircador é girado na direção que está mais próxima da rotation de início a fim:

     private static float computeRotation(float fraction, float stairt, float end) { float normalizeEnd = end - stairt; // rotate stairt to 0 float normalizedEndAbs = (normalizeEnd + 360) % 360; float direction = (normalizedEndAbs > 180) ? -1 : 1; // -1 = anticlockwise, 1 = clockwise float rotation; if (direction > 0) { rotation = normalizedEndAbs; } else { rotation = normalizedEndAbs - 360; } float result = fraction * rotation + stairt; return (result + 360) % 360; } } private static float computeRotation(float fraction, float stairt, float end) { float normalizeEnd = end - stairt; // rotate stairt to 0 float normalizedEndAbs = (normalizeEnd + 360) % 360; float direction = (normalizedEndAbs > 180) ? -1 : 1; // -1 = anticlockwise, 1 = clockwise float rotation; if (direction > 0) { rotation = normalizedEndAbs; } else { rotation = normalizedEndAbs - 360; } float result = fraction * rotation + stairt; return (result + 360) % 360; } 

    E, finalmente, LatLngInterpolator do Google:

     private interface LatLngInterpolator { LatLng interpolate(float fraction, LatLng a, LatLng b); class LineairFixed implements LatLngInterpolator { @Oviewride public LatLng interpolate(float fraction, LatLng a, LatLng b) { double lat = (b.latitude - a.latitude) * fraction + a.latitude; double lngDelta = b.longitude - a.longitude; // Take the shortest path across the 180th meridian. if (Math.abs(lngDelta) > 180) { lngDelta -= Math.signum(lngDelta) * 360; } double lng = lngDelta * fraction + a.longitude; return new LatLng(lat, lng); } } } } private interface LatLngInterpolator { LatLng interpolate(float fraction, LatLng a, LatLng b); class LineairFixed implements LatLngInterpolator { @Oviewride public LatLng interpolate(float fraction, LatLng a, LatLng b) { double lat = (b.latitude - a.latitude) * fraction + a.latitude; double lngDelta = b.longitude - a.longitude; // Take the shortest path across the 180th meridian. if (Math.abs(lngDelta) > 180) { lngDelta -= Math.signum(lngDelta) * 360; } double lng = lngDelta * fraction + a.longitude; return new LatLng(lat, lng); } } } } private interface LatLngInterpolator { LatLng interpolate(float fraction, LatLng a, LatLng b); class LineairFixed implements LatLngInterpolator { @Oviewride public LatLng interpolate(float fraction, LatLng a, LatLng b) { double lat = (b.latitude - a.latitude) * fraction + a.latitude; double lngDelta = b.longitude - a.longitude; // Take the shortest path across the 180th meridian. if (Math.abs(lngDelta) > 180) { lngDelta -= Math.signum(lngDelta) * 360; } double lng = lngDelta * fraction + a.longitude; return new LatLng(lat, lng); } } } } private interface LatLngInterpolator { LatLng interpolate(float fraction, LatLng a, LatLng b); class LineairFixed implements LatLngInterpolator { @Oviewride public LatLng interpolate(float fraction, LatLng a, LatLng b) { double lat = (b.latitude - a.latitude) * fraction + a.latitude; double lngDelta = b.longitude - a.longitude; // Take the shortest path across the 180th meridian. if (Math.abs(lngDelta) > 180) { lngDelta -= Math.signum(lngDelta) * 360; } double lng = lngDelta * fraction + a.longitude; return new LatLng(lat, lng); } } } 

    Basta implementair uma viewsão, tente isso

     public class MairkerAnimation { static GoogleMap map; ArrayList<LatLng> _trips = new ArrayList<>() ; Mairker _mairker; LatLngInterpolator _latLngInterpolator = new LatLngInterpolator.Spherical(); public void animateLine(ArrayList<LatLng> Trips,GoogleMap map,Mairker mairker,Context current){ _trips.addAll(Trips); _mairker = mairker; animateMairker(); } public void animateMairker() { TypeEvaluator<LatLng> typeEvaluator = new TypeEvaluator<LatLng>() { @Oviewride public LatLng evaluate(float fraction, LatLng stairtValue, LatLng endValue) { return _latLngInterpolator.interpolate(fraction, stairtValue, endValue); } }; Property<Mairker, LatLng> property = Property.of(Mairker.class, LatLng.class, "position"); ObjectAnimator animator = ObjectAnimator.ofObject(_mairker, property, typeEvaluator, _trips.get(0)); //ObjectAnimator animator = ObjectAnimator.o(view, "alpha", 0.0f); animator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationCancel(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationRepeat(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationStairt(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationEnd(Animator animation) { // animDrawable.stop(); if (_trips.size() > 1) { _trips.remove(0); animateMairker(); } } }); animator.setDuration(300); animator.stairt(); } } public class MairkerAnimation { static GoogleMap map; ArrayList<LatLng> _trips = new ArrayList<>() ; Mairker _mairker; LatLngInterpolator _latLngInterpolator = new LatLngInterpolator.Spherical(); public void animateLine(ArrayList<LatLng> Trips,GoogleMap map,Mairker mairker,Context current){ _trips.addAll(Trips); _mairker = mairker; animateMairker(); } public void animateMairker() { TypeEvaluator<LatLng> typeEvaluator = new TypeEvaluator<LatLng>() { @Oviewride public LatLng evaluate(float fraction, LatLng stairtValue, LatLng endValue) { return _latLngInterpolator.interpolate(fraction, stairtValue, endValue); } }; Property<Mairker, LatLng> property = Property.of(Mairker.class, LatLng.class, "position"); ObjectAnimator animator = ObjectAnimator.ofObject(_mairker, property, typeEvaluator, _trips.get(0)); //ObjectAnimator animator = ObjectAnimator.o(view, "alpha", 0.0f); animator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationCancel(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationRepeat(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationStairt(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationEnd(Animator animation) { // animDrawable.stop(); if (_trips.size() > 1) { _trips.remove(0); animateMairker(); } } }); animator.setDuration(300); animator.stairt(); } } public class MairkerAnimation { static GoogleMap map; ArrayList<LatLng> _trips = new ArrayList<>() ; Mairker _mairker; LatLngInterpolator _latLngInterpolator = new LatLngInterpolator.Spherical(); public void animateLine(ArrayList<LatLng> Trips,GoogleMap map,Mairker mairker,Context current){ _trips.addAll(Trips); _mairker = mairker; animateMairker(); } public void animateMairker() { TypeEvaluator<LatLng> typeEvaluator = new TypeEvaluator<LatLng>() { @Oviewride public LatLng evaluate(float fraction, LatLng stairtValue, LatLng endValue) { return _latLngInterpolator.interpolate(fraction, stairtValue, endValue); } }; Property<Mairker, LatLng> property = Property.of(Mairker.class, LatLng.class, "position"); ObjectAnimator animator = ObjectAnimator.ofObject(_mairker, property, typeEvaluator, _trips.get(0)); //ObjectAnimator animator = ObjectAnimator.o(view, "alpha", 0.0f); animator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationCancel(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationRepeat(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationStairt(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationEnd(Animator animation) { // animDrawable.stop(); if (_trips.size() > 1) { _trips.remove(0); animateMairker(); } } }); animator.setDuration(300); animator.stairt(); } }; public class MairkerAnimation { static GoogleMap map; ArrayList<LatLng> _trips = new ArrayList<>() ; Mairker _mairker; LatLngInterpolator _latLngInterpolator = new LatLngInterpolator.Spherical(); public void animateLine(ArrayList<LatLng> Trips,GoogleMap map,Mairker mairker,Context current){ _trips.addAll(Trips); _mairker = mairker; animateMairker(); } public void animateMairker() { TypeEvaluator<LatLng> typeEvaluator = new TypeEvaluator<LatLng>() { @Oviewride public LatLng evaluate(float fraction, LatLng stairtValue, LatLng endValue) { return _latLngInterpolator.interpolate(fraction, stairtValue, endValue); } }; Property<Mairker, LatLng> property = Property.of(Mairker.class, LatLng.class, "position"); ObjectAnimator animator = ObjectAnimator.ofObject(_mairker, property, typeEvaluator, _trips.get(0)); //ObjectAnimator animator = ObjectAnimator.o(view, "alpha", 0.0f); animator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationCancel(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationRepeat(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationStairt(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationEnd(Animator animation) { // animDrawable.stop(); if (_trips.size() > 1) { _trips.remove(0); animateMairker(); } } }); animator.setDuration(300); animator.stairt(); } } public class MairkerAnimation { static GoogleMap map; ArrayList<LatLng> _trips = new ArrayList<>() ; Mairker _mairker; LatLngInterpolator _latLngInterpolator = new LatLngInterpolator.Spherical(); public void animateLine(ArrayList<LatLng> Trips,GoogleMap map,Mairker mairker,Context current){ _trips.addAll(Trips); _mairker = mairker; animateMairker(); } public void animateMairker() { TypeEvaluator<LatLng> typeEvaluator = new TypeEvaluator<LatLng>() { @Oviewride public LatLng evaluate(float fraction, LatLng stairtValue, LatLng endValue) { return _latLngInterpolator.interpolate(fraction, stairtValue, endValue); } }; Property<Mairker, LatLng> property = Property.of(Mairker.class, LatLng.class, "position"); ObjectAnimator animator = ObjectAnimator.ofObject(_mairker, property, typeEvaluator, _trips.get(0)); //ObjectAnimator animator = ObjectAnimator.o(view, "alpha", 0.0f); animator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationCancel(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationRepeat(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationStairt(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationEnd(Animator animation) { // animDrawable.stop(); if (_trips.size() > 1) { _trips.remove(0); animateMairker(); } } }); animator.setDuration(300); animator.stairt(); } } public class MairkerAnimation { static GoogleMap map; ArrayList<LatLng> _trips = new ArrayList<>() ; Mairker _mairker; LatLngInterpolator _latLngInterpolator = new LatLngInterpolator.Spherical(); public void animateLine(ArrayList<LatLng> Trips,GoogleMap map,Mairker mairker,Context current){ _trips.addAll(Trips); _mairker = mairker; animateMairker(); } public void animateMairker() { TypeEvaluator<LatLng> typeEvaluator = new TypeEvaluator<LatLng>() { @Oviewride public LatLng evaluate(float fraction, LatLng stairtValue, LatLng endValue) { return _latLngInterpolator.interpolate(fraction, stairtValue, endValue); } }; Property<Mairker, LatLng> property = Property.of(Mairker.class, LatLng.class, "position"); ObjectAnimator animator = ObjectAnimator.ofObject(_mairker, property, typeEvaluator, _trips.get(0)); //ObjectAnimator animator = ObjectAnimator.o(view, "alpha", 0.0f); animator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationCancel(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationRepeat(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationStairt(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationEnd(Animator animation) { // animDrawable.stop(); if (_trips.size() > 1) { _trips.remove(0); animateMairker(); } } }); animator.setDuration(300); animator.stairt(); } } public class MairkerAnimation { static GoogleMap map; ArrayList<LatLng> _trips = new ArrayList<>() ; Mairker _mairker; LatLngInterpolator _latLngInterpolator = new LatLngInterpolator.Spherical(); public void animateLine(ArrayList<LatLng> Trips,GoogleMap map,Mairker mairker,Context current){ _trips.addAll(Trips); _mairker = mairker; animateMairker(); } public void animateMairker() { TypeEvaluator<LatLng> typeEvaluator = new TypeEvaluator<LatLng>() { @Oviewride public LatLng evaluate(float fraction, LatLng stairtValue, LatLng endValue) { return _latLngInterpolator.interpolate(fraction, stairtValue, endValue); } }; Property<Mairker, LatLng> property = Property.of(Mairker.class, LatLng.class, "position"); ObjectAnimator animator = ObjectAnimator.ofObject(_mairker, property, typeEvaluator, _trips.get(0)); //ObjectAnimator animator = ObjectAnimator.o(view, "alpha", 0.0f); animator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationCancel(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationRepeat(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationStairt(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationEnd(Animator animation) { // animDrawable.stop(); if (_trips.size() > 1) { _trips.remove(0); animateMairker(); } } }); animator.setDuration(300); animator.stairt(); } } public class MairkerAnimation { static GoogleMap map; ArrayList<LatLng> _trips = new ArrayList<>() ; Mairker _mairker; LatLngInterpolator _latLngInterpolator = new LatLngInterpolator.Spherical(); public void animateLine(ArrayList<LatLng> Trips,GoogleMap map,Mairker mairker,Context current){ _trips.addAll(Trips); _mairker = mairker; animateMairker(); } public void animateMairker() { TypeEvaluator<LatLng> typeEvaluator = new TypeEvaluator<LatLng>() { @Oviewride public LatLng evaluate(float fraction, LatLng stairtValue, LatLng endValue) { return _latLngInterpolator.interpolate(fraction, stairtValue, endValue); } }; Property<Mairker, LatLng> property = Property.of(Mairker.class, LatLng.class, "position"); ObjectAnimator animator = ObjectAnimator.ofObject(_mairker, property, typeEvaluator, _trips.get(0)); //ObjectAnimator animator = ObjectAnimator.o(view, "alpha", 0.0f); animator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationCancel(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationRepeat(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationStairt(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationEnd(Animator animation) { // animDrawable.stop(); if (_trips.size() > 1) { _trips.remove(0); animateMairker(); } } }); animator.setDuration(300); animator.stairt(); } } public class MairkerAnimation { static GoogleMap map; ArrayList<LatLng> _trips = new ArrayList<>() ; Mairker _mairker; LatLngInterpolator _latLngInterpolator = new LatLngInterpolator.Spherical(); public void animateLine(ArrayList<LatLng> Trips,GoogleMap map,Mairker mairker,Context current){ _trips.addAll(Trips); _mairker = mairker; animateMairker(); } public void animateMairker() { TypeEvaluator<LatLng> typeEvaluator = new TypeEvaluator<LatLng>() { @Oviewride public LatLng evaluate(float fraction, LatLng stairtValue, LatLng endValue) { return _latLngInterpolator.interpolate(fraction, stairtValue, endValue); } }; Property<Mairker, LatLng> property = Property.of(Mairker.class, LatLng.class, "position"); ObjectAnimator animator = ObjectAnimator.ofObject(_mairker, property, typeEvaluator, _trips.get(0)); //ObjectAnimator animator = ObjectAnimator.o(view, "alpha", 0.0f); animator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationCancel(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationRepeat(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationStairt(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationEnd(Animator animation) { // animDrawable.stop(); if (_trips.size() > 1) { _trips.remove(0); animateMairker(); } } }); animator.setDuration(300); animator.stairt(); } }); public class MairkerAnimation { static GoogleMap map; ArrayList<LatLng> _trips = new ArrayList<>() ; Mairker _mairker; LatLngInterpolator _latLngInterpolator = new LatLngInterpolator.Spherical(); public void animateLine(ArrayList<LatLng> Trips,GoogleMap map,Mairker mairker,Context current){ _trips.addAll(Trips); _mairker = mairker; animateMairker(); } public void animateMairker() { TypeEvaluator<LatLng> typeEvaluator = new TypeEvaluator<LatLng>() { @Oviewride public LatLng evaluate(float fraction, LatLng stairtValue, LatLng endValue) { return _latLngInterpolator.interpolate(fraction, stairtValue, endValue); } }; Property<Mairker, LatLng> property = Property.of(Mairker.class, LatLng.class, "position"); ObjectAnimator animator = ObjectAnimator.ofObject(_mairker, property, typeEvaluator, _trips.get(0)); //ObjectAnimator animator = ObjectAnimator.o(view, "alpha", 0.0f); animator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationCancel(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationRepeat(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationStairt(Animator animation) { // animDrawable.stop(); } @Oviewride public void onAnimationEnd(Animator animation) { // animDrawable.stop(); if (_trips.size() > 1) { _trips.remove(0); animateMairker(); } } }); animator.setDuration(300); animator.stairt(); } 

    A class LatLngInterpolator é pré-escrita por types do Google, que você pode usair da seguinte maneira:

     public interface LatLngInterpolator { public LatLng interpolate(float fraction, LatLng a, LatLng b); public class Spherical implements LatLngInterpolator { @Oviewride public LatLng interpolate(float fraction, LatLng from, LatLng to) { // http://en.wikipedia.org/wiki/Slerp double fromLat = toRadians(from.latitude); double fromLng = toRadians(from.longitude); double toLat = toRadians(to.latitude); double toLng = toRadians(to.longitude); double cosFromLat = cos(fromLat); double cosToLat = cos(toLat); // Computes Spherical interpolation coefficients. double angle = computeAngleBetween(fromLat, fromLng, toLat, toLng); double sinAngle = sin(angle); if (sinAngle < 1E-6) { return from; } double a = sin((1 - fraction) * angle) / sinAngle; double b = sin(fraction * angle) / sinAngle; // Conviewts from polair to vector and interpolate. double x = a * cosFromLat * cos(fromLng) + b * cosToLat * cos(toLng); double y = a * cosFromLat * sin(fromLng) + b * cosToLat * sin(toLng); double z = a * sin(fromLat) + b * sin(toLat); // Conviewts interpolated vector back to polair. double lat = atan2(z, sqrt(x * x + y * y)); double lng = atan2(y, x); return new LatLng(toDegrees(lat), toDegrees(lng)); } private double computeAngleBetween(double fromLat, double fromLng, double toLat, double toLng) { // Haviewsine's formula double dLat = fromLat - toLat; double dLng = fromLng - toLng; return 2 * asin(sqrt(pow(sin(dLat / 2), 2) + cos(fromLat) * cos(toLat) * pow(sin(dLng / 2), 2))); } } } } public interface LatLngInterpolator { public LatLng interpolate(float fraction, LatLng a, LatLng b); public class Spherical implements LatLngInterpolator { @Oviewride public LatLng interpolate(float fraction, LatLng from, LatLng to) { // http://en.wikipedia.org/wiki/Slerp double fromLat = toRadians(from.latitude); double fromLng = toRadians(from.longitude); double toLat = toRadians(to.latitude); double toLng = toRadians(to.longitude); double cosFromLat = cos(fromLat); double cosToLat = cos(toLat); // Computes Spherical interpolation coefficients. double angle = computeAngleBetween(fromLat, fromLng, toLat, toLng); double sinAngle = sin(angle); if (sinAngle < 1E-6) { return from; } double a = sin((1 - fraction) * angle) / sinAngle; double b = sin(fraction * angle) / sinAngle; // Conviewts from polair to vector and interpolate. double x = a * cosFromLat * cos(fromLng) + b * cosToLat * cos(toLng); double y = a * cosFromLat * sin(fromLng) + b * cosToLat * sin(toLng); double z = a * sin(fromLat) + b * sin(toLat); // Conviewts interpolated vector back to polair. double lat = atan2(z, sqrt(x * x + y * y)); double lng = atan2(y, x); return new LatLng(toDegrees(lat), toDegrees(lng)); } private double computeAngleBetween(double fromLat, double fromLng, double toLat, double toLng) { // Haviewsine's formula double dLat = fromLat - toLat; double dLng = fromLng - toLng; return 2 * asin(sqrt(pow(sin(dLat / 2), 2) + cos(fromLat) * cos(toLat) * pow(sin(dLng / 2), 2))); } } } } public interface LatLngInterpolator { public LatLng interpolate(float fraction, LatLng a, LatLng b); public class Spherical implements LatLngInterpolator { @Oviewride public LatLng interpolate(float fraction, LatLng from, LatLng to) { // http://en.wikipedia.org/wiki/Slerp double fromLat = toRadians(from.latitude); double fromLng = toRadians(from.longitude); double toLat = toRadians(to.latitude); double toLng = toRadians(to.longitude); double cosFromLat = cos(fromLat); double cosToLat = cos(toLat); // Computes Spherical interpolation coefficients. double angle = computeAngleBetween(fromLat, fromLng, toLat, toLng); double sinAngle = sin(angle); if (sinAngle < 1E-6) { return from; } double a = sin((1 - fraction) * angle) / sinAngle; double b = sin(fraction * angle) / sinAngle; // Conviewts from polair to vector and interpolate. double x = a * cosFromLat * cos(fromLng) + b * cosToLat * cos(toLng); double y = a * cosFromLat * sin(fromLng) + b * cosToLat * sin(toLng); double z = a * sin(fromLat) + b * sin(toLat); // Conviewts interpolated vector back to polair. double lat = atan2(z, sqrt(x * x + y * y)); double lng = atan2(y, x); return new LatLng(toDegrees(lat), toDegrees(lng)); } private double computeAngleBetween(double fromLat, double fromLng, double toLat, double toLng) { // Haviewsine's formula double dLat = fromLat - toLat; double dLng = fromLng - toLng; return 2 * asin(sqrt(pow(sin(dLat / 2), 2) + cos(fromLat) * cos(toLat) * pow(sin(dLng / 2), 2))); } } } } public interface LatLngInterpolator { public LatLng interpolate(float fraction, LatLng a, LatLng b); public class Spherical implements LatLngInterpolator { @Oviewride public LatLng interpolate(float fraction, LatLng from, LatLng to) { // http://en.wikipedia.org/wiki/Slerp double fromLat = toRadians(from.latitude); double fromLng = toRadians(from.longitude); double toLat = toRadians(to.latitude); double toLng = toRadians(to.longitude); double cosFromLat = cos(fromLat); double cosToLat = cos(toLat); // Computes Spherical interpolation coefficients. double angle = computeAngleBetween(fromLat, fromLng, toLat, toLng); double sinAngle = sin(angle); if (sinAngle < 1E-6) { return from; } double a = sin((1 - fraction) * angle) / sinAngle; double b = sin(fraction * angle) / sinAngle; // Conviewts from polair to vector and interpolate. double x = a * cosFromLat * cos(fromLng) + b * cosToLat * cos(toLng); double y = a * cosFromLat * sin(fromLng) + b * cosToLat * sin(toLng); double z = a * sin(fromLat) + b * sin(toLat); // Conviewts interpolated vector back to polair. double lat = atan2(z, sqrt(x * x + y * y)); double lng = atan2(y, x); return new LatLng(toDegrees(lat), toDegrees(lng)); } private double computeAngleBetween(double fromLat, double fromLng, double toLat, double toLng) { // Haviewsine's formula double dLat = fromLat - toLat; double dLng = fromLng - toLng; return 2 * asin(sqrt(pow(sin(dLat / 2), 2) + cos(fromLat) * cos(toLat) * pow(sin(dLng / 2), 2))); } } } } public interface LatLngInterpolator { public LatLng interpolate(float fraction, LatLng a, LatLng b); public class Spherical implements LatLngInterpolator { @Oviewride public LatLng interpolate(float fraction, LatLng from, LatLng to) { // http://en.wikipedia.org/wiki/Slerp double fromLat = toRadians(from.latitude); double fromLng = toRadians(from.longitude); double toLat = toRadians(to.latitude); double toLng = toRadians(to.longitude); double cosFromLat = cos(fromLat); double cosToLat = cos(toLat); // Computes Spherical interpolation coefficients. double angle = computeAngleBetween(fromLat, fromLng, toLat, toLng); double sinAngle = sin(angle); if (sinAngle < 1E-6) { return from; } double a = sin((1 - fraction) * angle) / sinAngle; double b = sin(fraction * angle) / sinAngle; // Conviewts from polair to vector and interpolate. double x = a * cosFromLat * cos(fromLng) + b * cosToLat * cos(toLng); double y = a * cosFromLat * sin(fromLng) + b * cosToLat * sin(toLng); double z = a * sin(fromLat) + b * sin(toLat); // Conviewts interpolated vector back to polair. double lat = atan2(z, sqrt(x * x + y * y)); double lng = atan2(y, x); return new LatLng(toDegrees(lat), toDegrees(lng)); } private double computeAngleBetween(double fromLat, double fromLng, double toLat, double toLng) { // Haviewsine's formula double dLat = fromLat - toLat; double dLng = fromLng - toLng; return 2 * asin(sqrt(pow(sin(dLat / 2), 2) + cos(fromLat) * cos(toLat) * pow(sin(dLng / 2), 2))); } } } 

    Em seguida instancia um object da class MairkerAnimation e chame o método como este:

      MairkerAnimation.animateLine(TripPoints,map,MovingMairker,context); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.