谷歌Android地图API V2中心标志 [英] Android Google maps API V2 center markers

查看:153
本文介绍了谷歌Android地图API V2中心标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法,使地图放大尽可能但保留所有屏幕上的标记在同一时间。 我有一个非均匀的形状六个标志。我想的只是把自己的心和定位的地图,但我还是后来不知道多远编程我可以在地图上放大。

这些标记改变位置每次创建地图的时间。理想的情况是我有放大,因此所有的地图都包含在视图中的脚本。

所以,你明白了。我创建的标志之一从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);
 

*从另一篇文章中得到了:<一href="http://stackoverflow.com/questions/14828217/android-map-v2-zoom-to-show-all-the-markers/14828739#14828739">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中心标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆