How to get Google Maps object inside a Fragment

前端 未结 7 1910
走了就别回头了
走了就别回头了 2021-02-19 01:26

I am using fragments in my application and I am new for this. There is a fragment in which I want to display Google Map and want to get its object, for this I have a fragment in

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-19 02:07

    Revised code:

    Your xml file-

     
    

    Your java file (only relevant code)-

    View  view = null, mapView = null;
    private GoogleMap mMap;
    
    view = inflater.inflate(R.layout.findmycar, container,false);
    FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
            SupportMapFragment supportMapFragment = (SupportMapFragment) fragmentManager
                    .findFragmentById(R.id.map);
    
    mMap = supportMapFragment.getMap();
    mapView = (View) view.findViewById(R.id.map);
    

提交回复
热议问题