7

Is there a way to make a map zoom in as far as possible but keeping all of the markers on screen at the same time. I have six markers in a non uniform shape. I was thinking of just taking their centre and locating the map to that, but I still then do not know how far programmatically I can zoom in the map.

These markers change location every time the map is created. Ideally I would have a script that zooms the map in so all are included in the view.

So you understand. I am creating the markers one at a time from json with the following line in a loop.

mMap.addMarker(new MarkerOptions().position(new LatLng(lat,lng)).title(c.getString("title")));
4

2 回答 2

24

您应该使用 CameraUpdate 类(可能)执行所有程序化地图移动。

为此,首先计算所有标记的边界,如下所示:

LatLngBounds.Builder builder = new LatLngBounds.Builder();
for each (Marker m : markers) {
    builder.include(m.getPosition());
}

LatLngBounds bounds = builder.build();

然后使用工厂获取运动描述对象:CameraUpdateFactory:

int padding = 0; // offset from edges of the map in pixels
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);

最后移动地图:

googleMap.moveCamera(cu);

或者如果你想要一个动画:

googleMap.animateCamera(cu);

*来自另一篇文章:Android 地图 v2 缩放以显示所有标记

于 2013-07-12T11:33:55.137 回答
1

你可能想看看这个:

https://developers.google.com/maps/documentation/android/views#sharing_camera_position

于 2013-07-12T11:33:55.950 回答