izac89
izac89

Reputation: 3930

Issue with Android's GoogleMap.CancelableCallback()

Given the following code:

 System.out.println("begin");     
 LatLng me=new LatLng(myLat,myLongt);
 MainActivity.this.googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(me, 15), new GoogleMap.CancelableCallback() {
        @Override
        public void onFinish() {
            System.out.println("onFinish");
        }

        @Override
        public void onCancel() {
            System.out.println("onCancel");
        }
    });

The onFinish() method is called not when the animation is finished, instead, it's called really close to the time in which the animation fires.

05-24 19:54:26.025  23172-23172/com.bbb.gps I/System.out﹕ begin
05-24 19:54:26.140  23172-23172/com.bbb.gps I/System.out﹕ onfinish

The animation is taking ~1.5 seconds, so, there is a problem here.

What am I doing wrong?

Upvotes: 2

Views: 254

Answers (1)

Kay_N
Kay_N

Reputation: 997

Implement delay for animate camera like below:

MainActivity.this.googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(me, 15), 1500, new GoogleMap.CancelableCallback()

Also,

return true;

It will make sure that the events are consumed.

Upvotes: 1

Related Questions