Set Map Bounds with different padding

我的梦境 提交于 2019-12-05 01:40:12

This is an older question and maybe the asker found the solution but here it is for anyone who faces same problem in future. Set the individual padding using

googleMap.setPadding(left, top, right, bottom)

and then use

googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds.build(), 0))

Don't forget to set the paddings back to 0 (or whatever they were before) after you are done. Because unlike newLatLngBounds(), the paddings set by setPadding() are permanent.

The question is old but for more informations please check here.

If the bound is supposed to be applied for a specific action, setting the map padding may not be a good solution cause it's permanent.

apply a padding of 100 and above to see the effect in your map. Bellow is a simple example.

final int MAP_BOUND_PADDING = 180;  /* In dp */  
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (LatLng latLng : listLatLng) { //listLatLngis a list of latLng to bound. You can put two if you want. 
    builder.include(latLng);
}
LatLngBounds bounds = builder.build();
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, MAP_BOUND_PADDING);
mMap.animateCamera(cu);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!