SupportMapFragment - cannot cast from Fragment to MapFragment

I can either use getFragmentManager() or getSupportFragmentManager().

There should be no debate here. If getSupportFragmentManager() is available to you, then you are using the Android Support package's backport of fragments, and this is the method that you must use.

When I opt for getSupportFragmentManager(), Eclipse doesn't like it and gives me the error "Cannot cast from Fragment to MapFragment".

That is because you should not be using MapFragment. You are using the Android Support package's backport of fragments, and therefore you must use SupportMapFragment.


This is what i had to do, because i was working under level 11;

    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.SupportMapFragment;
    import android.support.v4.app.FragmentActivity;

    public class MapaActivity extends FragmentActivity {

    private GoogleMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mapa);

        map =  ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.mapa)).getMap();
    }
}