如何在Google Maps Android API v2中为超过2个位置执行CameraUpdate?

时间:2016-08-06 08:07:43

标签: android google-maps

我想在Google地图中显示多个标记,并在单个视图中显示它们。我在地图上显示了所有标记但我在使用CameraUpdate时遇到了困难。请帮忙。提前谢谢。

1 个答案:

答案 0 :(得分:1)

您必须创建一个LatLngBounds:

List<Marker> myMarkers; //your list of markers
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for(Marker m: myMarkers){
    builder.include(m.getPosition());
}
LatLngBounds bounds = builder.build();
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 20);//20 is padding, use it to avoid markers on the border of the map view
mMap.animateCamera(cu);