问题描述
Google地图文档
根据
使用moveCamera时的映射:
已解决
onDeviceHeadingChange(){if(!cameraIsMoving){cameraIsMoving = trueval cameraPosition = CameraPosition.builder(mMap.cameraPosition).target(myLatLng).bearing(myBearing).tilt(50f).建造()val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition)mMap.animateCamera(cameraUpdate,500,对象:GoogleMap.CancelableCallback {覆盖fun onFinish(){cameraIsMoving = false}覆盖fun onCancel(){cameraIsMoving = false}})}}
这将我带到一个新问题为什么GoogleMap.moveCamera()可以处理这些呼叫?但是GoogleMap.animateCamera()不能?
这对我有用
LatLng initialLocation = new LatLng(纬度,经度);gmap.animateCamera(CameraUpdateFactory.newLatLngZoom(initialLocation,18.0f));
我使用它与LatLng动画化到特定位置的地图,虽然我从未尝试过倾斜
Google Maps document
According to Google maps document, in order to apply a CameraUpdate to the map, we can either move the camera instantly(by using GoogleMap.moveCamera(CameraUpdate)) or animate the camera smoothly(by using GoogleMap.animateCamera(CameraUpdate)).
What I did
So I started by using GoogleMap.moveCamera(CameraUpdate). The map can be loaded just fine. However, when I used GoogleMap.animateCamera(CameraUpdate), the map can't be loaded. What I saw was just a gray screen or a blur map. The map would be fully loaded or became clear again unless I moved it manually.
Could anyone please tell me what is the problem? Does it require somethings else when working with GoogleMap.animateCamera()?
Updated:I just found a big mistake in my code and really sorry that I had not described it clear enough.I used GMap.animateCamera() to update the camera whenever the heading of the device changed(used rotation sensor...). This happens too fast so cameraAnimation() can never finish its work. that's why the map can't be fully loaded either.
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)
}
Map when use animateCamera:
Map when use moveCamera:
Solved
onDeviceHeadingChange(){
if(!cameraIsMoving){
cameraIsMoving = true
val cameraPosition = CameraPosition.builder(mMap.cameraPosition)
.target(myLatLng)
.bearing(myBearing)
.tilt(50f)
.build()
val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition)
mMap.animateCamera(cameraUpdate, 500, object: GoogleMap.CancelableCallback{
override fun onFinish() {
cameraIsMoving = false
}
override fun onCancel() {
cameraIsMoving = false
}
})
}
}
This take me to a new questionWhy GoogleMap.moveCamera() can handle those call? but GoogleMap.animateCamera() can't?
this works for me
LatLng initialLocation = new LatLng(latitude, longitude);
gmap.animateCamera(CameraUpdateFactory.newLatLngZoom(initialLocation, 18.0f));
I use it to animate map to a particular location with LatLng, I have never tried tilt though
这篇关于使用GoogleMap.AnimateCamera()时,android google maps不会加载地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!