是否可以将相机设置为多个目标动画

问题描述 投票:-1回答:1

是否可以将Google Maps摄像机移动到多个位置?例如移至位置A,然后移至位置B,等等。

有关如何执行此操作的任何想法?

问候

android google-maps android-camera
1个回答
0
投票
// The below Coordinates numbers are just for the demo LatLng placeALatLng = new LatLng(31.11, 23.8859); LatLng placeBLatLng = new LatLng(23.8859, 11.4211); LatLng placeCALatLng = new LatLng(11.4211, 23.8859); private ArrayList<LatLng> places = new ArrayList<>(); int count = 0; private void startAnimating(){ places.add(placeALatLng); places.add(placeBLatLng); places.add(placeCALatLng); animateToNextPlace(); } private void animateToNextPlace(){ if(count >= places.size()){ return; } animateCameraToLocation(places.get(count)); count++; } private void animateCameraToLocation(LatLng placeLatLng){ final int zoom = 12; final int duration = 1000; // 1 second mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(placeLatLng, zoom), duration, new GoogleMap.CancelableCallback() { @Override public void onFinish() { //Animate to next Location animateToNextPlace(); } @Override public void onCancel() { } }); }

或者,如果您只是想简单地移动摄像机而没有持续时间,并且不停地移动到下一个位置,请使用以下方法:

CameraPosition cameraPosition = new CameraPosition.Builder()
                            .target(new LatLng(placeA.getLatitude(), placeA.getLongitude()))
                            .zoom(15)
                            .build();
mMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
© www.soinside.com 2019 - 2024. All rights reserved.