0

Can you add a v2 google map to an android app without adding it via an xml file?

user1923613
  • 626
  • 5
  • 11
  • 31

1 Answers1

1

Yes you can using the support map fragment as follows:

public class LocationFragment extends SupportMapFragment {  

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = super.onCreateView(inflater, container, savedInstanceState);   
        return v;
    }


}

and you can add this Location fragment to your container as follows:

LocationFragment mapFragment = new LocationFragment();
            FragmentTransaction ft = getFragmentManager.beginTransaction();
            ft.add(R.id.your_container_id, mapFragment);
            ft.commit();
Karan_Rana
  • 2,813
  • 2
  • 26
  • 35