问题描述
有没有一种方法,使地图放大尽可能但保留所有屏幕上的标记在同一时间。我有一个非均匀的形状六个标志。我想的只是把自己的心和定位的地图,但我还是后来不知道多远编程我可以在地图上放大。
这些标记改变位置每次创建地图的时间。理想的情况是我有放大,因此所有的地图都包含在视图中的脚本。
所以,你明白了。我创建的标志之一从JSON在循环中以下行的时候。
mMap.addMarker(新MarkerOptions()位置(新的经纬度(纬度,经度))称号(c.getString(标题)));
您应该使用CameraUpdate类来实现(可能)所有方案的地图的动作。
要做到这一点,首先计算出所有的标记的范围,像这样:
LatLngBounds.Builder建设者=新LatLngBounds.Builder();
每个(M标记:标记){
builder.include(m.getPosition());
}
的LatLngBounds边界= builder.build();
然后通过工厂获得一个运动的描述对象:CameraUpdateFactory:
内部填充= 0; //从像素图的边缘偏移
CameraUpdate立方米= CameraUpdateFactory.newLatLngBounds(边界,填充);
最后,移动地图:
googleMap.moveCamera(CU);
或者,如果你想要一个动画:
googleMap.animateCamera(CU);
*从另一篇文章中得到了:Android地图V2缩放显示
所有标记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")));
You should use the CameraUpdate class to do (probably) all programmatic map movements.
To do this, first calculate the bounds of all the markers like so:
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for each (Marker m : markers) {
builder.include(m.getPosition());
}
LatLngBounds bounds = builder.build();
Then obtain a movement description object by using the factory: CameraUpdateFactory:
int padding = 0; // offset from edges of the map in pixels
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
Finally move the map:
googleMap.moveCamera(cu);
Or if you want an animation:
googleMap.animateCamera(cu);
*Got from another post: Android map v2 zoom to show all the markers
这篇关于谷歌Android地图API V2中心标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!