moveCamera和animateCamera不能再次运行 [英] moveCamera and animateCamera don't work the second time
问题描述
我有以下更新我的地图的方法:
private void setCamera(){
if(currentLocation != null){
String [] coords = currentLocation.split(,,2);
CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(Double.parseDouble(coords [0]),Double.parseDouble(coords [1])));
CameraUpdate zoom = CameraUpdateFactory.zoomTo(5);
mMap.moveCamera(center);
mMap.animateCamera(zoom);
$ / code $ / pre
第一次打开后立即调用这个方法应用程序,并且这种方法工作正常。但在那之后,我又去了另一个片段,然后又去了第一个片段。在这种情况下,该方法被调用, currentLocation
不等于null, center
得到正确的 LatLng
对象,但是我的地图视图没有改变,缩放比例小于5.
有什么不对?
解决方案我最终解决了这个问题。我改变了以前的代码,如下所示:
private void setCamera(){
if(currentLocation!= null){
String [] coords = currentLocation.split(,,2);
CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(Double.parseDouble(coords [0]),Double.parseDouble(coords [1])));
CameraUpdate zoom = CameraUpdateFactory.zoomTo(5);
mapFragment.getMap()。moveCamera(center);
mapFragment.getMap()。animateCamera(zoom);
}
}
现在地图显示正确。
I have the following method for updating my map:
private void setCamera() {
if (currentLocation != null) {
String[] coords = currentLocation.split(",", 2);
CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(Double.parseDouble(coords[0]), Double.parseDouble(coords[1])));
CameraUpdate zoom = CameraUpdateFactory.zoomTo(5);
mMap.moveCamera(center);
mMap.animateCamera(zoom);
}
}
The first time I invoke this method immediately after opening the app, and this method is working fine. But after that I go to another fragment and then to the first fragment again. And in this case the method was invoked, currentLocation
didn't equal null, center
got the right LatLng
object, but my map view didn't change and zoom is less than 5.
What is wrong?
解决方案 Eventually I've resolved this issue. I changed the previous code as follows:
private void setCamera() {
if (currentLocation != null) {
String[] coords = currentLocation.split(",", 2);
CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(Double.parseDouble(coords[0]), Double.parseDouble(coords[1])));
CameraUpdate zoom = CameraUpdateFactory.zoomTo(5);
mapFragment.getMap().moveCamera(center);
mapFragment.getMap().animateCamera(zoom);
}
}
And now the map is displayed correctly.
这篇关于moveCamera和animateCamera不能再次运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!