2016-11-22 51 views
1

我想放大的GoogleMap的位置,其显示为标志,并在此之后,滚动该标志由像素的权利, 目前我结合2分的动作像上面这样这样的:缩放地图到某个位置,将其移动到右

LatLng point = new LatLng(lat,lon); 

MarkerOptions endMarker = new MarkerOptions().position(point); 

googleMap.addMarker(endMarker); 

googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(point, 15f)); 

int screenWidth = getScreenWidth(); 

int margin = (int) getResources().getDimension(R.dimen.double_standard_margin_padding); 

new Handler().postDelayed(() -> googleMap.animateCamera(CameraUpdateFactory.scrollBy(-(screenWidth - margin) * 3/8, 0), new GoogleMap.CancelableCallback() { 
        @Override 
        public void onFinish() { 

        } 

        @Override 
        public void onCancel() { 

        } 
       }), 1000); 

正如你所看到的,我加2层的方法来做到这一点:

googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(point, 15f)); 

googleMap.animateCamera(CameraUpdateFactory.scrollBy(-(screenWidth - margin) * 3/8, 0) 

我不得不推迟行动,移动地图,因为我们不知道什么时候该地图被放大

有时候地图上动弹不得(onCancel()),所以我不能收到预期的UI。

可能有人知道如何在只有一个办法归档?

回答

1

我几次遇到同样的问题,我创建了一个CameraUpdateAnimator,它执行带有给定延迟(如果需要)的CameraUpdates链,并允许移动或动画摄像头(请参阅my project on GitHub)。我认为,它可以在你的情况下非常有用:

CameraUpdateAnimator animator = new CameraUpdateAnimator(mMap, this); // Parameters: a GoogleMap instance and an OnCameraIdleListener to return the control to (can be null) 
animator.add(CameraUpdateFactory.newLatLngZoom(point, 15f), false, 0); // Move the camera without delay 
animator.add(CameraUpdateFactory.scrollBy(-(screenWidth - margin) * 3/8, 0), true, 1000); // Animate the camera with a 1000 milliseconds delay 
animator.execute(); 
相关问题