I need to move Camera to cover all Markers on it. So, I build LatLngBounds
and then try to call mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(latLng
Since Google Maps SDK was updated to recent versions onCameraChangeListener became deprecated. I've also faced with this problem and I discovered that onCameraIdleListener does the similar trick. As I see so far it's callback method onCameraIdle
called always after onMapReady
. So my approach looks like this piece of code (considering it put in Activity
) for Google Maps SDK 9.6+:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set content view and call getMapAsync() on MapFragment
}
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
map.setOnCameraIdleListener(this);
// other initialization stuff
}
@Override
public void onCameraIdle() {
/*
Here camera is ready and you can operate with it.
you can use 2 approaches here:
1. Update the map with data you need to display and then set
map.setOnCameraIdleListener(null) to ensure that further events
will not call unnecessary callback again.
2. Use local boolean variable which indicates that content on map
should be updated
*/
}