Android maps - Markers Bounds at the center of top

2020-02-14 16:43发布

问题:

I have Android Map Extension attached under actionBar.

I have couple of markers, lets say 2000.

Than I have ArrayList of selected 3 markers upon some constant condition, nevermind.

I want to zoom and move map to include this selected 3 markers at max possible zoom.

It's an easy task, from this forum I found an easy way to do it :

LatLngBounds bounds = new LatLngBounds.Builder().include(new LatLng(maxLat, maxLon)).include(new LatLng(minLat, minLon)).build();
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0));

I have map perfectly zoomed at this 3 markers.

Now is hard part.

When I zoom at this markers I have layout that covers bottom half of map.

I want to archive the same situation but on upper half of map only.

Resizing map is not an option.

I've tried to enlarge my boundaries 2 times vertically but it doesn't help

Thank you for your help in advance

回答1:

GoogleMap.setPadding is what you need. Simply set bottom to half of the height of your map.