Google Maps Android API v2: Visualizing the search radius with the helping of ValueAnimator
Asked Answered
S

1

10

I want to add an animated circle to Google Maps view similar to the circle you see on this image.

enter image description here

The circle should be pulsing from the center to the largest radius indicating current user's location and the area of searching.

Here is relevant code block

Circle circle = mMap.addCircle(new CircleOptions()
     .center(new LatLng(lat, lon))
     .strokeColor(Color.CYAN).radius(1000));
    valueAnimator = new ValueAnimator();
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
        float animatedFraction = valueAnimator.getAnimatedFraction();
         circle.setRadius(animatedFraction * 1000);
         circle.setStrokeWidth(1 + animatedFraction * 7);
         }
        });

With this code I am only able to see static circle stroke without any animation.

Any help will be appreciated. Thanks in advance.

Shiner answered 24/6, 2013 at 14:31 Comment(0)
M
31

Simply :)

    final Circle circle = MAP.addCircle(new CircleOptions().center(EGYPT)
            .strokeColor(Color.CYAN).radius(100));

    ValueAnimator vAnimator = new ValueAnimator();
    vAnimator.setRepeatCount(ValueAnimator.INFINITE);
    vAnimator.setRepeatMode(ValueAnimator.RESTART);  /* PULSE */
    vAnimator.setIntValues(0, 100);
    vAnimator.setDuration(1000);
    vAnimator.setEvaluator(new IntEvaluator());
    vAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
    vAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float animatedFraction = valueAnimator.getAnimatedFraction();
            // Log.e("", "" + animatedFraction);
            circle.setRadius(animatedFraction * 100);
        }
    });
    vAnimator.start();
Mandy answered 23/7, 2013 at 2:25 Comment(2)
Animation works until the markers will be shown. When markers are shown animation disappears. No matter where I call vAnimator.start(); it is not visualized anymore but at the same time I can see in the LogCat that it is processing. Do you have any assumptions why animation is not visualized with markers?Shiner
My circle has a fill color, but it dissappears when it's animated. What should i do?Fornix

© 2022 - 2024 — McMap. All rights reserved.