上的标记组中心的Andr​​oid谷歌地图? [英] Center android google map on group of markers?

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

问题描述

我有一堆我在其中加载到谷歌地图的标记。我的问题是,照相机是不ontop的标记。我可以集中它在我的所有标记的​​顶部?

I have a bunch of markers in which I load onto a google map. My problem is that, the camera is not ontop of the markers. Can I center it on top of all my markers?

我加入我的标记与此code:

I am adding my markers with this code:

for(int i = 0; i < jsonArray.length(); i++) {

                String breweryName = jsonArray.getJSONObject(i).getString("brewery");
                String lat = jsonArray.getJSONObject(i).getString("lat");
                String lng = jsonArray.getJSONObject(i).getString("lng");
                String bID = jsonArray.getJSONObject(i).getString("breweryID");

                double latD = Double.parseDouble(lat);
                double lngD = Double.parseDouble(lng);



                m.addMarker(new MarkerOptions()
                        .position(new LatLng(latD, lngD))
                        .title(breweryName));


            }

我看着堆,发现了这个问题,这是我的一样:

I looked on stack and found this question, which is the same as mine:

的Andr​​oid谷歌地图API V2中心标志

但不是它的背后多少背景和我不知道如何实现它。

But there isnt much context behind it and am not sure how to implement it.

推荐答案

您可以将特定范围内动画的相机。比方说,你有标记的ArrayList,类似的信息(这也可以LatLngs列表,双打,任何包含经/纬度的标志)

You can animate your camera within specific bounds. Let's say you have an ArrayList of markers, something like (this could also be a list of LatLngs, doubles, anything contains the latitude/longitude for your marker)

List<MarkerOptions> markers = new ArrayList<MarkerOptions>();

然后,您可以确保它们都是可见的在地图上通过执行以下操作

You can then make sure they are all visible on your map by doing the following

LatLngBounds.Builder builder = new LatLngBounds.Builder();
LatLng position;
for(int i = 0; i < markers.size(); i++){
    position = markers.get(i).getPosition();
    builder.include(new LatLng(position.latitude, position.longitude));
}
LatLngBounds bounds = builder.build();
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 15));

这篇关于上的标记组中心的Andr​​oid谷歌地图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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