How to Add Uber Car Animation in Android? 

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s