If you want to place a map inside of a fragment then I suggest you to use the MapView
object in your layout instead of the MapFragment
, here is a code that works for me:
The layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.gms.maps.MapView
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
And the fragment itself:
public class MapFragment extends Fragment {
private static final String TAG = MapFragment.class.getSimpleName();
private MapView mapView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.new_mapview, container, false);
// Gets the MapView from the XML layout and creates it
mapView = (MapView) view.findViewById(R.id.mapview);
mapView.onCreate(savedInstanceState);
return view;
}
@Override
public void onPause() {
mapView.onPause();
super.onPause();
}
@Override
public void onResume() {
mapView.onResume();
super.onResume();
}
@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
}