简体   繁体   中英

Android Google Maps animating every location

I have an ArrayList of LatLng, and in a forloop of onMapReady(GoogleMap googleMap) I would like to animate moving from location to another in order.

I tried doing this in a for loop:

        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currLatLng,10), 1000, null);

and the animation happens only at the last location.

How would I go about doing so? Should I use the last parameter of animateCamera() method? (Cancellable Callback)

My instinct was correct.
The last parameter in animateCamera is a CancellableCallback() interface.
What I did is made a method called a nimateToLocationAtIndex(int index)

And then called:

mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 10), 2000, new GoogleMap.CancelableCallback() {
        @Override
        public void onFinish() {
            // Placing a marker on the position after animated
            Marker marker = mMap.addMarker(markerOptions);
            animateLocationMovement(i+1);
        }

This animates the locations as I wanted, although I ran into another issue where the map at the next location isn't loaded so it may seem like the animation is laggy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM