简体   繁体   English

我可以将2个cameraUpdate与一个animateCamera一起使用吗?

[英]Can I use 2 cameraUpdates with one animateCamera?

I am trying to zoom on a map 我正在尝试放大地图

CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(mBounds, this.getResources().getDisplayMetrics().widthPixels,
                        height, padding);
mMap.animateCamera(cameraUpdate, duration, null); 

And after that I want to scroll the map vertically 之后,我想垂直滚动地图

CameraUpdate cameraUpdate =
        CameraUpdateFactory.scrollBy(0, amountToScroll);
    mMap.animateCamera(cameraUpdate, duration, null);

The thing is ... it is not working. 问题是...不起作用。 If I call the scroll right after the zoom, only the scroll is taken into account. 如果在缩放后立即调用滚动条,则仅考虑滚动条。 If I scroll the map once the zoom animation is finished I will have 2 animations. 如果缩放动画结束后滚动地图,则将有2个动画。

I would like to do both operations with the same animation, is it possible? 我想用相同的动画进行这两种操作,可以吗?

If you call animateCamera multiple times, only the last one will finish its action. 如果多次调用animateCamera ,则只有最后一个将完成其操作。

The easy fix would be to use moveCamera instead of the first call to animateCamera , but that's not a nice solution from UX perspective. 简单的解决方法是使用moveCamera而不是第一次调用animateCamera ,但是从UX角度来看,这不是一个好的解决方案。

The other way would be to do the math yourself and fill mBounds with the bounds you really want to show. 另一种方法是自己进行数学运算,并用真正要显示的边界填充mBounds

The easiest way to do it is to use CancelableCallback. 最简单的方法是使用CancelableCallback。 You should check the first action is complete and then call the second: 您应该检查第一个动作是否完成,然后调用第二个:

mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, size.x, height, 0), new CancelableCallback() {

                @Override
                public void onFinish() {
                    CameraUpdate cu_scroll = CameraUpdateFactory.scrollBy(0, 500);
                    mMap.animateCamera(cu_scroll);
                }

                @Override
                public void onCancel() {
                }
            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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