Google Maps Fragment Doesn't Load
Solution 1:
In the XML file, use class="com.google.android.gms.maps.SupportMapFragment"
.
In you main class, use:
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
Instead of:
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
Solution 2:
To add SupportMapFragment
to your project you need to add google-support-v4
library and google map libraries
. You can read about how to do that in a blog post I wrote, Google Maps API V2.
Solution 3:
FragmentActivity
is provided by the Android Support Library v4 to allow Android platforms before Android 3 (Honeycomb) to use fragments. With Honeycomb and later, fragments are supported using by the standard Activity
class
The catch is, depending on the activity class you choose, you cannot use the same fragment class:
- with
android.support.v4.app.FragmentActivity
, you muse useandroid.support.v4.app.Fragment
- with
android.app.Activity
, you must useandroid.app.Fragment
Note the package difference.
Now, with respect to Google Maps v2 for Android, you have two Fragment implementations:
MapFragment
which extendsandroid.app.Fragment
for Honeycomb and laterSupportMapFragment
which extendsandroid.support.v4.app.Fragment
for support of the older Android versions
So, as you use FragmentActivity
, you must use the SupportMapFragment
implementation for your application.
Post a Comment for "Google Maps Fragment Doesn't Load"