上的标记组中心的Android谷歌地图? [英] Center android google map on group of markers?
问题描述
我有一堆我在其中加载到谷歌地图的标记。我的问题是,照相机是不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:
但不是它的背后多少背景和我不知道如何实现它。
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));
这篇关于上的标记组中心的Android谷歌地图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!