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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With