安卓谷歌地图:如何同步移动标记和相机



我在谷歌地图和相机上同时移动标记时遇到问题。

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

当位置发生变化时,我想将标记移动到新位置,同时移动相机,因此它始终以地图为中心(效果看起来像只有地图移动(。

我正在通过如下所示的代码来执行此操作,

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

但是,有时会有一些闪烁。看起来地图和标记在不同的线程中渲染,因此有时标记会在相机之前移动,有时反之亦然。如果首先移动标记,则会将其绘制在不再位于中心的位置,然后在相机移动后不久,标记将在中心再次绘制,从而导致闪烁。

如何使标记和相机同步移动?

谢谢。

试试这个:

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

最新更新