对多个标记谷歌地图摄像头位置 [英] Google map camera position on multiple markers
本文介绍了对多个标记谷歌地图摄像头位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用谷歌地图API 2并显示在上面的多个标记。我的问题是,我想我的相机被放置在我所有的标记。 我已经做了单标记为
myMap.moveCamera(CameraUpdateFactory.newLatLngZoom(MyLocation,22));
解决方案
我已经用下面的方式看到视野中的所有标记。它会束缚你的图形页面,包括所有的纬度龙的位置,你有你的数组列表。
//潘看到视野中的所有标记。
//无法放大到边界,直到地图的大小。
最后查看图形页面= getSupportFragmentManager()findFragmentById(R.id.map).getView()。
如果(mapView.getViewTreeObserver()。的isAlive()){
mapView.getViewTreeObserver()。addOnGlobalLayoutListener(新OnGlobalLayoutListener(){
@燮pressLint(NewApi)
@覆盖
公共无效onGlobalLayout(){
LatLngBounds.Builder BLD =新LatLngBounds.Builder();
的for(int i = 0; I< YOUR_ARRAYLIST.size();我++){
经纬度LL =新经纬度(YOUR_ARRAYLIST.get(ⅰ).getPos()getLat(),YOUR_ARRAYLIST.get(ⅰ).getPos()getLon());
bld.include(Ⅱ);
}
的LatLngBounds边界= bld.build();
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(范围,70));
。mapView.getViewTreeObserver()removeGlobalOnLayoutListener(本);
}
});
}
希望这将有助于。
I am using google map API 2 and showing multiple markers on it. My problem it that I want my camera to be positioned on all my markers. I have done it for single marker as
myMap.moveCamera(CameraUpdateFactory.newLatLngZoom(MyLocation, 22));
解决方案
I have Used Below Way to see all markers in view. It will Bound your Mapview including all the Lat-Long Location you have in your arraylist.
// Pan to see all markers in view.
// Cannot zoom to bounds until the map has a size.
final View mapView = getSupportFragmentManager().findFragmentById(R.id.map).getView();
if (mapView.getViewTreeObserver().isAlive()) {
mapView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@SuppressLint("NewApi")
@Override
public void onGlobalLayout() {
LatLngBounds.Builder bld = new LatLngBounds.Builder();
for (int i = 0; i < YOUR_ARRAYLIST.size(); i++) {
LatLng ll = new LatLng(YOUR_ARRAYLIST.get(i).getPos().getLat(), YOUR_ARRAYLIST.get(i).getPos().getLon());
bld.include(ll);
}
LatLngBounds bounds = bld.build();
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 70));
mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
}
Hope it Will Help.
这篇关于对多个标记谷歌地图摄像头位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文