如何连接 CameraUpdate 动画
How to concat CameraUpdate animations
我想要运行一个CameraUpdateFactory.newLatLngBounds
动画,docs声明:
Returns a CameraUpdate that transforms the camera such that the
specified latitude/longitude bounds are centered on screen within a
bounding box of specified dimensions at the greatest possible zoom
level. You can specify additional padding, to further restrict the
size of the bounding box. The returned CameraUpdate has a bearing of 0
and a tilt of 0.
但我不希望它在屏幕上居中,我想向上移动焦点区域,想象一下 "align_parent_top"。所以我有一个CameraUpdateFactory.scrollBy
来实现它。
CameraUpdate move = CameraUpdateFactory.newLatLngBounds(
builder.build(),
getUtils().getScreenAbsoluteWith(),
mAvailableHeight,
mDefaultMapPadding);
CameraUpdate scroll = CameraUpdateFactory.scrollBy(0,mAvailableHeight + mDefaultMapPadding));
然后:
mMap.animateCamera(move, new GoogleMap.CancelableCallback() {
@Override
public void onFinish() {
mMap.animateCamera(scroll);
@Override
public void onCancel() {}
});
不幸的是,我真正想要的是 运行 将两个动画放在一起。或者,以某种方式创建一个不会在屏幕上居中的 CameraUpdateFactory.newLatLngBounds
。
有什么想法吗?谢谢。
只需将 Lat/Lng 边界转换为屏幕像素,然后添加像素,然后将像素转换为 Lat\Lng 返回:
...
private GoogleMap mGoogleMap;
...
// convert LatLng bounds to screen coords
Point pointNortheast = projection.toScreenLocation(latLngBounds.northeast);
Point pointSouthwest = projection.toScreenLocation(latLngBounds.southwest);
// modify bounds in screen coords
pointNortheast.y += scrollByPixel;
pointSouthwest.y += scrollByPixel;
// convert screen coords back to LatLng
LatLng geoNortheast = projection.fromScreenLocation(pointNortheast);
LatLng geoSouthwest = projection.fromScreenLocation(pointSouthwest);
LatLngBounds modifiedBounds = new LatLngBounds(geoSouthwest, geoNortheast);
// animate camera to new bounds
mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(modifiedBounds, 0));
...
我想要运行一个CameraUpdateFactory.newLatLngBounds
动画,docs声明:
Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude bounds are centered on screen within a bounding box of specified dimensions at the greatest possible zoom level. You can specify additional padding, to further restrict the size of the bounding box. The returned CameraUpdate has a bearing of 0 and a tilt of 0.
但我不希望它在屏幕上居中,我想向上移动焦点区域,想象一下 "align_parent_top"。所以我有一个CameraUpdateFactory.scrollBy
来实现它。
CameraUpdate move = CameraUpdateFactory.newLatLngBounds(
builder.build(),
getUtils().getScreenAbsoluteWith(),
mAvailableHeight,
mDefaultMapPadding);
CameraUpdate scroll = CameraUpdateFactory.scrollBy(0,mAvailableHeight + mDefaultMapPadding));
然后:
mMap.animateCamera(move, new GoogleMap.CancelableCallback() {
@Override
public void onFinish() {
mMap.animateCamera(scroll);
@Override
public void onCancel() {}
});
不幸的是,我真正想要的是 运行 将两个动画放在一起。或者,以某种方式创建一个不会在屏幕上居中的 CameraUpdateFactory.newLatLngBounds
。
有什么想法吗?谢谢。
只需将 Lat/Lng 边界转换为屏幕像素,然后添加像素,然后将像素转换为 Lat\Lng 返回:
...
private GoogleMap mGoogleMap;
...
// convert LatLng bounds to screen coords
Point pointNortheast = projection.toScreenLocation(latLngBounds.northeast);
Point pointSouthwest = projection.toScreenLocation(latLngBounds.southwest);
// modify bounds in screen coords
pointNortheast.y += scrollByPixel;
pointSouthwest.y += scrollByPixel;
// convert screen coords back to LatLng
LatLng geoNortheast = projection.fromScreenLocation(pointNortheast);
LatLng geoSouthwest = projection.fromScreenLocation(pointSouthwest);
LatLngBounds modifiedBounds = new LatLngBounds(geoSouthwest, geoNortheast);
// animate camera to new bounds
mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(modifiedBounds, 0));
...