I need your help... I work on it until 3 days. My app is working with fragments. One of these fragments has to display a map from the Google Maps V2 api for Android.
Use SupportMapFragment to overcome this error:
In fragment layout
<fragment
android:id="@+id/googleMap"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
In Your Fragment onCreateView
SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.googleMap);
if (mapFragment != null) {
mapFragment.getMapAsync(this);
}
Since your layout is in the Fragment's
layout, therefore the SupportMapFragment
is the child layout of your fragment. Hence use getChildFragmentManager()
which is Fragment's FragmentManager
Use MapView instead of MapFragment in your Fragment's layout. Remember to call MapView's lifecycle methods:
as described here.
Btw. you shouldn't be using MapFragment, only SupportMapFragment and support library.
Edit:
If you switch to support library, you can use code from comment #1 here: http://code.google.com/p/gmaps-api-issues/issues/detail?id=5064#c1