gpt4 book ai didi

安卓谷歌地图 : how to move a marker and the camera synchronously?

转载 作者:搜寻专家 更新时间:2023-11-01 08:46:49 25 4
gpt4 key购买 nike

我在同时移动 GoogleMap 和相机上的标记时遇到问题。

我在 map 上有一个标记,如果用户不滚动 map ,它通常位于 map 的中心。标记表示当前位置,由外部源提供。

当位置发生变化时,我想将标记移动到新的位置,同时移动相机,使其始终以 map 为中心(效果看起来只是 map 移动) .

我正在通过如下代码执行此操作,

LatLng latlng = new LatLng(rawData.latitude, rawData.longitude);
mMarker.setPosition(latlng); // move the marker

CameraUpdate update = CameraUpdateFactory.newLatLngZoom(latlng, mCurrZoom);
mMap.moveCamera(update); // move the camera

但是,有时会有一些闪烁。看起来 map 和标记是在不同的线程中渲染的,所以有时标记会在相机之前移动,有时反之亦然。如果先移动marker,会在不在中心的地方绘制,然后在camera移动后不久,marker会重新绘制到中心,从而造成闪烁。

如何让marker和camera同步移动?

谢谢。

最佳答案

试试这个:

mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(yourLatitude, yourLongitude), zommvalue));

关于安卓谷歌地图 : how to move a marker and the camera synchronously?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27466742/

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