我有一个 LatLng 点列表,我想在 GoogleMap 上显示为标记。我目前正在计算一个适合我所有观点的相机视图,方法如下:
首先,我用我的所有点计算一个 LatLngBounds。
Iterator<LatLng> i = items.iterator(); LatLngBounds.Builder builder = LatLngBounds.builder(); while (i.hasNext()) { builder.include(i.next()); } LatLngBounds bounds = builder.build();
然后我使用适当的方法:
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, padding);
该更新提供了我所有观点的良好视图,并带有一些不错的填充。
问题
我想为 paddingTop、paddingBottom、paddingLeft 和 paddingRight 应用不同的值。也就是说,我两边都没有,然后我在顶部有一个浮动工具栏(关于50dp
),在底部有一个浮动卡片(关于200dp
)。
如果我不添加填充,一些点将被顶部工具栏或底部卡片覆盖。
如果我添加最大填充 ( 200dp
),则顶部、左侧和右侧会有巨大的间隙。任何想法?
__________________________
| ___________o__________ |
| | | |
| |____________________|o|
| o |
| o |
| o |
| MAP |
| o |
| o |
| ______________________ |
| | | |
|o| | |
| | |o|
| |____________________| |
|____________________o___|
我现在唯一的想法是,以像素为单位获取地图宽度,以 Lng 为单位获取地图宽度(未明确定义),找到像素/lng 比率,将所需的填充从像素转换为 lng,然后重新计算 LatLngBounds 添加一个假点(一个对于每一边),这与我原来的界限相距甚远。