谷歌地图文档
根据Google地图文档,为了将CameraUpdate应用于地图,我们可以立即移动相机(通过使用GoogleMap.moveCamera(CameraUpdate))或平滑地设置相机动画(通过使用GoogleMap.animateCamera(CameraUpdate))。
我做了什么
所以我开始使用 GoogleMap.moveCamera(CameraUpdate)。地图可以正常加载。但是,当我使用GoogleMap.animateCamera(CameraUpdate)时,无法加载地图。我看到的只是一个灰色的屏幕或一张模糊的地图。除非我手动移动地图,否则地图将完全加载或再次变得清晰。
谁能告诉我有什么问题吗?使用 GoogleMap.animateCamera() 时还需要其他东西吗?
更新:我刚刚在我的代码中发现了一个大错误,非常抱歉我没有描述得足够清楚。每当设备的航向发生变化时(使用旋转传感器...),我就使用 GMap.animateCamera() 来更新相机。这种情况发生得太快,因此cameraAnimation()永远无法完成其工作。这就是地图也无法完全加载的原因。
onDeviceHeadingChange(){
val cameraPosition = CameraPosition.builder(mMap.cameraPosition)
.target(myLatLng)
.bearing(myBearing)
.tilt(50f)
.build()
val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition)
// the map will be loaded just fine with this method
// mMap.moveCamera(cameraUpdate)
// the problem appeared when I update camera with aniteCamera()
mMap.animateCamera(cameraUpdate, 500, null)
}
Run Code Online (Sandbox Code Playgroud)
解决了
onDeviceHeadingChange(){
if(!cameraIsMoving){
cameraIsMoving = true
val cameraPosition = CameraPosition.builder(mMap.cameraPosition)
.target(myLatLng)
.bearing(myBearing)
.tilt(50f)
.build()
val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) …
Run Code Online (Sandbox Code Playgroud)