简体   繁体   English

强制animateCamera完成动画

[英]Force animateCamera to complete animation

I'm trying to force the camera to animate to a zoom level and coordinate that describes as precisely as possible the area occupied by a list of LatLng coordinates. 我正在尝试迫使相机动画化为缩放级别和坐标,以尽可能准确地描述由LatLng坐标列表占据的区域。

So far, I have the following: 到目前为止,我有以下内容:

private void focusListOfCoords(Collection<LatLng> coords) {
  LatLngBounds.Builder coordsBoundsBuilder = new LatLngBounds.Builder();
  for (LatLng coord : coords) {
    coordsBoundsBuilder.include(coord);
  }
  LatLngBounds coordsBounds = coordsBoundsBuilder.build();
  CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(coordsBounds, 50);
  mMap.animateCamera(cameraUpdate);
}

The code above, when zoomed all the way out on the whole world simply pans the view slightly to center on the center point of the bounds. 上面的代码在整个世界上一望无际时,只是将视图稍微平移到以边界的中心点为中心。 It does not zoom in. 它不会放大。

If I replace mMap.animateCamera(cameraUpdate) with mMap.moveCamera(cameraUpdate) , the projection changes the zoom level (too far in every case, but that's beside the point) and centers as expected. 如果我将mMap.animateCamera(cameraUpdate)替换为mMap.moveCamera(cameraUpdate) ,则投影会更改缩放级别(在每种情况下都太远了,但是在该点附近)并按预期居中。

After trying to troubleshoot this, I noticed that if I implement the CancelableCallback for the animateCamera method, I can see that the animation is being cancelled. 在尝试解决此问题之后,我注意到如果为animateCamera方法实现CancelableCallback ,则可以看到动画已被取消。

Is there a way to force the animation to finish? 有没有办法强迫动画完成? If not, how can I hunt down the cause of the animation being cancelled? 如果不是,我如何找出动画被取消的原因?

Edit : The solution can be found in this question: Android- animateCamera with CameraUpdateFactory.newCameraPosition does NOT zoom 编辑 :可以在以下问题中找到解决方案: 具有CameraUpdateFactory.newCameraPosition的Android- animateCamera无法缩放

To summarize, my listener method that was calling the animation was returning false which cancelled the animation. 总而言之,我正在调用动画的侦听器方法返回false,这取消了动画。

You can try to use a different approach to your implementation. 您可以尝试使用其他方法来实施。

One is passing CameraUpdateFactory.newLatLngZoom(latlng, zoom) to animateCamera . 一种是将CameraUpdateFactory.newLatLngZoom(latlng, zoom)传递给animateCamera You can specify the zoom level using this. 您可以使用此指定缩放级别。 More info on that here . 有关此的更多信息。

Or you can build your CameraView first before passing it to animateCamera . 或者,您可以先构建CameraView然后再将其传递给animateCamera You can check out the docs here . 您可以在此处查看文档。

Not really sure why or how it is trigerring onCancel() . 不太确定为什么或如何触发onCancel onCancel() Maybe something is being fired right after your animateCamera call. 也许您的animateCamera通话后立即触发了某些操作。 Try to use the duration parameter to alter the speed of the animation and check for changes. 尝试使用duration参数来更改动画的速度并检查更改。

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

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