gpt4 book ai didi

android - 如何连接 CameraUpdate 动画

转载 作者:行者123 更新时间:2023-11-29 19:02:34 24 4
gpt4 key购买 nike

我想运行一个 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));
...

关于android - 如何连接 CameraUpdate 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48463819/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com