Android的 - 谷歌地图移动相机位置到另一个 [英] Android - google map move camera from position to another

查看:627
本文介绍了Android的 - 谷歌地图移动相机位置到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不久,我想知道怎样才能从当前位置摄像机移动到另外一个动画。这里是我的尝试:

Shortly, I want to know how I can move the camera from current position to another one with animation. Here is my try:

 mapView.moveCamera(CameraUpdateFactory.newLatLngZoom(targetPos, 3));
 mapView.animateCamera(CameraUpdateFactory.zoomTo(5), 2000, null);

不过,谷歌地图确实从某些位置到目标移动相机。我怎样才能将它从A到目标移动,其中一个就是有些位置我可以设置?先谢谢了。

But Google map does move camera from some position to the target. How can I set it move from A to target, which A is some position I can set? Thanks in advance.

推荐答案

看code在CameraDemoActivity地图样本。 要转到你需要有一个CameraPosition的位置。

Look at the code in CameraDemoActivity in the maps sample. To go to a position you need to have a CameraPosition.

static final CameraPosition SYDNEY =
        new CameraPosition.Builder().target(new LatLng(-33.87365, 151.20689))
                .zoom(15.5f)
                .bearing(0)
                .tilt(25)
                .build();



public void onGoToSydney(View view) {   
    changeCamera(CameraUpdateFactory.newCameraPosition(SYDNEY), new CancelableCallback() {
        @Override
        public void onFinish() {
            Toast.makeText(getBaseContext(), "Animation to Sydney complete", Toast.LENGTH_SHORT)
                    .show();
        }

        @Override
        public void onCancel() {
            Toast.makeText(getBaseContext(), "Animation to Sydney canceled", Toast.LENGTH_SHORT)
                    .show();
        }
    });
}


/**
 * Change the camera position by moving or animating the camera depending on the state of the
 * animate toggle button.
 */
private void changeCamera(CameraUpdate update, CancelableCallback callback) {
    if (mAnimateToggle.isChecked()) {
        if (mCustomDurationToggle.isChecked()) {
            int duration = mCustomDurationBar.getProgress();
            // The duration must be strictly positive so we make it at least 1.
            mMap.animateCamera(update, Math.max(duration, 1), callback);
        } else {
            mMap.animateCamera(update, callback);
        }
    } else {
        mMap.moveCamera(update);
    }
}

这篇关于Android的 - 谷歌地图移动相机位置到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆