I was able to animate a basic circle on Android Google Maps v2, but I wanted to take it a step forward. I wanted the animated circle to be similar to Tinders animated circles, is that possible?
Example: http://jsfiddle.net/Y3r36/9/
Right now, I am getting a fidgety animation that is very unacceptable. Here is my code:
public void onMapReady(GoogleMap map) {
double latitude = 33.750587;
double longitude = -84.4199173;
LatLng latLng = new LatLng(latitude,longitude);
map.moveCamera(CameraUpdateFactory.newLatLng(latLng));
map.animateCamera(CameraUpdateFactory.zoomTo(13));
map.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title("Marker"));
final Circle circle = mMap.addCircle(new CircleOptions()
.center(new LatLng(latitude,longitude))
.radius(50).fillColor(0x5500ff00).strokeWidth(0)
);
ValueAnimator valueAnimator = new ValueAnimator();
valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
valueAnimator.setRepeatMode(ValueAnimator.RESTART);
valueAnimator.setIntValues(0, 100);
valueAnimator.setDuration(1000);
valueAnimator.setEvaluator(new IntEvaluator());
valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float animatedFraction = valueAnimator.getAnimatedFraction();
Log.e("", "" + animatedFraction);
circle.setRadius(animatedFraction * 100);
}
});
valueAnimator.start();
I'm open to any suggestions. Thank you
July 18, 2022 The Maps SDK for Android version 18.1. 0 is now available. See the Release Notes for information about this release and for all previous releases. If you are a new user, see Set Up in the Google Cloud Console to start the installation process.
Instead of trying to render a single image, Google breaks down the map into smaller tiles, and then places them next to each other to make up a single bigger picture — just like a mosaic. The primary reason for this is image size.
The fidgety animation is a known issue. To work around this problem you could use a GroundOverlay instead of the circle.
Here's a sample to obtain the effect you mentioned:
private static final int DURATION = 3000;
private void showRipples(LatLng latLng) {
GradientDrawable d = new GradientDrawable();
d.setShape(GradientDrawable.OVAL);
d.setSize(500,500);
d.setColor(0x5500ff00);
d.setStroke(0, Color.TRANSPARENT);
Bitmap bitmap = Bitmap.createBitmap(d.getIntrinsicWidth()
, d.getIntrinsicHeight()
, Bitmap.Config.ARGB_8888);
// Convert the drawable to bitmap
Canvas canvas = new Canvas(bitmap);
d.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
d.draw(canvas);
// Radius of the circle
final int radius = 50;
// Add the circle to the map
final GroundOverlay circle = map.addGroundOverlay(new GroundOverlayOptions()
.position(latLng, 2 * radius).image(BitmapDescriptorFactory.fromBitmap(bitmap)));
// Prep the animator
PropertyValuesHolder radiusHolder = PropertyValuesHolder.ofFloat("radius", 0, radius);
PropertyValuesHolder transparencyHolder = PropertyValuesHolder.ofFloat("transparency", 0, 1);
ValueAnimator valueAnimator = new ValueAnimator();
valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
valueAnimator.setRepeatMode(ValueAnimator.RESTART);
valueAnimator.setValues(radiusHolder, transparencyHolder);
valueAnimator.setDuration(DURATION);
valueAnimator.setEvaluator(new FloatEvaluator());
valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float animatedRadius = (float) valueAnimator.getAnimatedValue("radius");
float animatedAlpha = (float) valueAnimator.getAnimatedValue("transparency");
circle.setDimensions(animatedRadius * 2);
circle.setTransparency(animatedAlpha);
}
});
// start the animation
valueAnimator.start();
}
Now for the ripple effect :
showRipples(latLng);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
showRipples(latLng);
}
}, DURATION - 500);
UPDATE : This issue has been fixed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With