In your Fragment layout put a MapView widget:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- My TextView -->
<com.google.android.gms.maps.MapView android:id="@+id/my_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:uiZoomControls="false"
map:uiCompass="false"
map:uiRotateGestures="false"
map:uiScrollGestures="true"
map:uiTiltGestures="false"
map:uiZoomGestures="true"
android:visibility="visible"/>
<!-- My Button and eventually others widgets -->
</RelativeLayout>
Your fragment will inflate your custom layout with the MapView and the others widgets you need in . Here a pseudo code about how to setup the MapView.
public class MyCustomFragmentWithMap extends Fragment {
private MapView mMapView = null;
private GoogleMap mMyMap = null;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
try {
MapsInitializer.initialize(getActivity());
} catch (GooglePlayServicesNotAvailableException err) {
Log.e(TAG, err.getMessage(), err);
}
mMapView = (MapView)getView().findViewById(R.id.my_map);
mMapView.onCreate(savedInstanceState);
mMyMap = mMapView.getMap();
mMyMap.setMyLocationEnabled(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.my_custom_fragment_with_map, container, false);
/* All the widgets setup as usual ... */
return view;
}
@Override
public void onResume() {
super.onResume();
if (mMapView != null)
mMapView.onResume();
}
@Override
public void onPause() {
if (mMapView != null)
mMapView.onPause();
super.onPause();
}
@Override
public void onDestroy() {
if (mMapView != null)
mMapView.onDestroy();
super.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
if (mMapView != null)
mMapView.onLowMemory();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mMapView != null)
mMapView.onSaveInstanceState(outState);
}
I'm assuming that you already know how to setup the Google Maps Android API v2 (obtaining the api key, setting permissions in manifest and all the boring stuffs :-P).