好的,我认为我找到了一个解决方案:首先,我们生成一个最小的矩形,以容纳多边形,也称为LatLngBounds
对象。然后,我们将相机移动到适合作为参数提供的LatLngBounds
上。
主要调用:
final int POLYGON_PADDING_PREFERENCE = 200;
final LatLngBounds latLngBounds = getPolygonLatLngBounds(polygon);
googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds, POLYGON_PADDING_PREFERENCE));
辅助函数:
private static LatLngBounds getPolygonLatLngBounds(final List<LatLng> polygon) {
final LatLngBounds.Builder centerBuilder = LatLngBounds.builder();
for (LatLng point : polygon) {
centerBuilder.include(point);
}
return centerBuilder.build();
}