对多个标记谷歌地图摄像头位置多个、标记、摄像头、位置

2023-09-05 10:01:52 作者:七年之痒°

我使用谷歌地图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 O开发大会上推出

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.