MoveCamera and animateCamera do not work a second time

I have the following way to update 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 call this method immediately after opening the application, and this method works fine. But after that, I move on to another fragment, and then to the first fragment again. And in this case, the method was called, currentLocation not equal to zero, center received the correct LatLng object, but my map view did not change, and the scale is less than 5. What is wrong?

+6
source share
1 answer

In the end, I solved this problem. I modified 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.

+3
source

All Articles