MapFragment in Fragment, alternatives?

后端 未结 8 614
猫巷女王i
猫巷女王i 2020-12-08 10:32

I need your help... I work on it until 3 days. My app is working with fragments. One of these fragments has to display a map from the Google Maps V2 api for Android.

8条回答
  •  温柔的废话
    2020-12-08 11:05

    In Your Class

          SupportMapFragment mSupportMapFragment;
          private GoogleMap googleMap;
          int ZOOM_LEVEL=15;
    
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
           View mTrackView = inflater
                .inflate(R.layout.mylayout, container, false);
            mSupportMapFragment = SupportMapFragment.newInstance();
            FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
            fragmentTransaction.add(R.id.mapwhere, mSupportMapFragment);
            fragmentTransaction.commit();
    
            return mTrackView;
        }
    
          @Override
          public void onStart() {
            // TODO Auto-generated method stub
              super.onStart();
    
            if(mSupportMapFragment!=null){
    
                googleMap = mSupportMapFragment.getMap();
                if(googleMap!=null){
                googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
                googleMap.getUiSettings().setMyLocationButtonEnabled(false);
                googleMap.setMyLocationEnabled(false);
    
    
                CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(
                        new LatLng(12.12122,
                            17.22323), ZOOM_LEVEL);
                googleMap.animateCamera(cameraUpdate);
                  }
                }
          }
    

    mylayout.xml

        
         
    
    
          
    
        
    

提交回复
热议问题