Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to adjust zoom level to fit boundary and then center map in marker offset?

I have a google map (com.google.android.gms.maps.GoogleMap) where I have some markers set.

I am able to, separately,

1) adjust zoom level and center the map on a boundary:

mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(getZoomBounds(), 10));

and

2) center the map above one of the markers:

LatLng poiSelectedLatLng = new LatLng(markerSelected.getPosition().latitude 
    + offset, markerSelected.getPosition().longitude);

mMap.animateCamera(CameraUpdateFactory.newLatLng(poiSelectedLatLng));

but, for the life of me, I can't just do both, adjust the zoom level using newLatLngBounds and then center the map somewhere else. Whatever I do last is what I see happening in the map.

How do I do this?

like image 452
Miki Avatar asked Jun 18 '13 15:06

Miki


People also ask

How do you change the zoom level on a map?

You can change the zoom level of the map using simple steps. Step 1 Go to Add or Edit Map page . Step 2 Select 'Default zoom level' in the 'Map Information section'. Step 3 click save map and see the changes.


1 Answers

For future visitors this is how you can chain camera animations:

map.animateCamera(CameraUpdateFactory.newLatLngBounds(getZoomBounds(), 10), 2000, new CancelableCallback() {

    @Override
    public void onFinish() {
        LatLng poiSelectedLatLng = new LatLng(markerSelected.getPosition().latitude + offset, markerSelected.getPosition().longitude);
        map.animateCamera(CameraUpdateFactory.newLatLng(poiSelectedLatLng));
    }

    @Override
    public void onCancel() {
    }
});

Also see AnimateCameraChainingExampleActivity.java for an example how to chain infinitely.

like image 194
MaciejGórski Avatar answered Oct 02 '22 03:10

MaciejGórski