[英]How to adjust zoom level to fit boundary and then center map in marker offset?
I have a google map (com.google.android.gms.maps.GoogleMap) where I have some markers set. 我有一个谷歌地图(com.google.android.gms.maps.GoogleMap),我有一些标记设置。
I am able to, separately, 我能够,分开,
1) adjust zoom level and center the map on a boundary: 1)调整缩放级别并将地图置于边界中心:
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(getZoomBounds(), 10));
and 和
2) center the map above one of the markers: 2)将地图置于其中一个标记上方:
LatLng poiSelectedLatLng = new LatLng(markerSelected.getPosition().latitude
+ offset, markerSelected.getPosition().longitude);
mMap.animateCamera(CameraUpdateFactory.newLatLng(poiSelectedLatLng));
but, for the life of me, I can't just do both, adjust the zoom level using newLatLngBounds and then center the map somewhere else. 但是,对于我的生活,我不能同时做两件事,使用newLatLngBounds调整缩放级别,然后将地图置于其他地方。 Whatever I do last is what I see happening in the map. 无论我做什么,都是我在地图上看到的。
How do I do this? 我该怎么做呢?
For future visitors this is how you can chain camera animations: 对于未来的访客,您可以使用相机动画链接:
map.animateCamera(CameraUpdateFactory.newLatLngBounds(getZoomBounds(), 10), 2000, new CancelableCallback() {
@Override
public void onFinish() {
LatLng poiSelectedLatLng = new LatLng(markerSelected.getPosition().latitude + offset, markerSelected.getPosition().longitude);
map.animateCamera(CameraUpdateFactory.newLatLng(poiSelectedLatLng));
}
@Override
public void onCancel() {
}
});
Also see AnimateCameraChainingExampleActivity.java for an example how to chain infinitely. 另请参阅AnimateCameraChainingExampleActivity.java以获取无限链接的示例。
Try using both moveCamera
and animateCamera
... 尝试同时使用moveCamera
和animateCamera
......
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(getZoomBounds(), 10));
LatLng poiSelectedLatLng = new LatLng(markerSelected.getPosition().latitude
+ offset, markerSelected.getPosition().longitude);
mMap.animateCamera(CameraUpdateFactory.newLatLng(poiSelectedLatLng));
moveCamera
will move directly to that spot while animateCamera
will provide the moving effect. moveCamera
将直接移动到那个位置,而animateCamera
将提供移动效果。 They are linear in nature so one will happen after the other however layering them as I have done above will provide the potential effect you are looking for. 它们本质上是线性的,所以一个将在另一个之后发生,但是如上所述将它们分层将提供您正在寻找的潜在效果 。
If you are trying to see the actual movement of both calls on the UI you will need to register for the callback post the completion of the animation as needed. 如果您试图在UI上查看两个调用的实际移动,则需要在完成动画时根据需要注册回调。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.