作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在同时移动 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/
我是一名优秀的程序员,十分优秀!