Add Google Maps API V2 in a fragment

前端 未结 11 1977
误落风尘
误落风尘 2020-11-29 03:00

I\'m trying to show the map from the Google Maps API V2 in fragment. I tried with the SupportMapFragment, but I can\'t get the expected output. Also I\'m a beginner on this

11条回答
  •  悲哀的现实
    2020-11-29 03:26

    Using MapView within Fragment under Google Maps Android API v2.0

    public class MapFragment extends Fragment {
    
        MapView m;
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, 
                Bundle savedInstanceState) {
            // inflat and return the layout
            View v = inflater.inflate(R.layout.map_fragment, container, false);
            m = (MapView) v.findViewById(R.id.mapView);
            m.onCreate(savedInstanceState);
    
            return v;
        }
    
        @Override
        public void onResume() {
            super.onResume();
            m.onResume();
        }
    
        @Override
        public void onPause() {
            super.onPause();
            m.onPause();
        }
    
        @Override
        public void onDestroy() {
            super.onDestroy();
            m.onDestroy();
        }
    
        @Override
        public void onLowMemory() {
            super.onLowMemory();
            m.onLowMemory();
        }
    }
    

    http://ucla.jamesyxu.com/?p=287

提交回复
热议问题