Create Food Order Tracking app using Android Timeline View Library

Create UberCar Animation with Android Library

How to Add Uber Car Animation in Android
How to Add Uber Car Animation in Android
I found a question on Quora about How to add Uber car animation in Android application. I really like this question and found a solution which help you if want to do this in your application.

Solution is UberCarAnimation is an Android library which showing movement of car on map like in Uber.

  • Parse the “overview_polyline” from the JSON by providing the appropriate GET parameters. For eg:
"https://maps.googleapis.com/maps/api/directions/json?" +
"mode=driving&"
+ "transit_routing_preference=less_driving&"
+ "origin=" + latitude + "," + longitude + "&"
+ "destination=" + destination + "&"
+ "key=" + getResources().getString(R.string.google_directions_key)

  • Decode the polyline which will provide you with list of latitudes and longitudes that is List<LatLng> to be apt.
  • Create a value animator by providing the ofFloatValue, setting duration and adding update listener in Handler
ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);
valueAnimator.setDuration(3000);
valueAnimator.setInterpolator(new LinearInterpolator());
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
//CODE
});

  • Finally set position of marker to the new position, also evaluating the bearing between the consecutive points so that it seems car is turning literally and finally update camera as:
marker.setPosition(newPos);
marker.setAnchor(0.5f, 0.5f);
marker.setRotation(getBearing(startPosition, newPos));
mMap.moveCamera(CameraUpdateFactory
.newCameraPosition
(new CameraPosition.Builder()
target(newPos)
.zoom(15.5f)
.build()));



See full article: Add Uber Car Animation Android

Comments