在 CameraUpdateFactory.newLatLngBounds 周围添加额外的填充

tim*_*imv 4 java android google-maps

我需要在我显示的地图上的标记周围添加额外的填充。

这是到目前为止的代码,但顶部和底部或西部和东部标记位于屏幕边缘。

 @Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;


    mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
        @Override
        public void onMapLoaded() {
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            for (int i = 0; i < arrayList.size(); i++) {
                options.position(latlngs.get(i));
                options.title(arrayList.get(i).getArea().toString());
                options.snippet(arrayList.get(i).getRegion().toString());
                mMap.addMarker(options);
                builder.include(latlngs.get(i));
            }
            LatLngBounds bounds = builder.build();
            int padding = 0;
            CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, padding);

            mMap.moveCamera(cameraUpdate);            }
    });

}
Run Code Online (Sandbox Code Playgroud)

这是我得到的: 我目前得到的

这就是我要的: 我需要的 那么如何添加一些填充,以便我可以看到所有标记,但不会将标记靠在地图边缘?感谢您提供任何意见。

Shw*_*dha 6

设置填充值> 0
示例:
int padding = 50;


Ale*_*r G 6

我还建议@Zumry Mohamed从线程中提出的解决方案:Android map v2 Zoom to show all the labels,这最适合我:

width = getResources().getDisplayMetrics().widthPixels;
height = getResources().getDisplayMetrics().heightPixels;
padding = (int) (width * 0.20); // offset from edges of the map - 20% of screen
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds,, width, height, padding);
Run Code Online (Sandbox Code Playgroud)