Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move camera position to fit LatLngBounds with regard to marker height

I want to move camera to position to fit LatLngBounds with regard to marker height. So far I'm able for fit the anchors of markers with this code:

LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (Marker marker : markerList) {
    builder.include(marker.getPosition());
}
LatLngBounds bounds = builder.build();

int padding = getActivity().getResources().getDimensionPixelSize(R.dimen.home_map_padding); // offset from edges of the map in pixels
cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, padding);
mGoogleMap.animateCamera(cameraUpdate);

It produces output like this: my output so far As you can see there's empty space at the bottom (this is int padding). I'd like to have the padding to be equal like this:

enter image description here

like image 482
Marian Paździoch Avatar asked Mar 02 '15 15:03

Marian Paździoch


People also ask

How to move camera in Android studio?

You can move the camera by making API calls or using user gestures. To move the camera by calling an API, you should use the CameraUpdate object and the moveCamera() method. With various properties of the CameraUpdate , you can specify the camera position, animations, callbacks, and so on.


1 Answers

Your question is similar to the one posted here:

Defining a CameraUpdate with LatLngBounds with different padding values

The solution is to set the top padding of the actual GoogleMap to the height of your marker icon.

Something like this will do:

Drawable drawable = <YOUR DRAWABLE HERE>;
final int padding = drawable.getIntrinsicHeight();
map.setPadding(0, padding, 0, 0);

Looks like this with my custom marker image (rulers inserted for comparison):

enter image description here

like image 187
Baz Avatar answered Sep 29 '22 11:09

Baz