Google maps 从supportmapfragment返回的空映射

Google maps 从supportmapfragment返回的空映射,google-maps,Google Maps,我正在尝试在我的Android应用程序中使用谷歌地图API v2。我已经使用以下代码以编程方式添加了地图片段,然后我尝试从我的SupportMapFragment中获取Google地图,但是我总是返回空结果,即使地图在屏幕上显示得很好…非常感谢任何帮助 谢谢 public class MapActivity extends BaseFragmentActivity { private SchoolType mSchoolType=SchoolType.ALL; private

我正在尝试在我的Android应用程序中使用谷歌地图API v2。我已经使用以下代码以编程方式添加了地图片段,然后我尝试从我的SupportMapFragment中获取Google地图,但是我总是返回空结果,即使地图在屏幕上显示得很好…非常感谢任何帮助

谢谢

public class MapActivity extends BaseFragmentActivity {


    private SchoolType mSchoolType=SchoolType.ALL;
    private GoogleMap mMap;
    private UiSettings mUiSettings;
    private SupportMapFragment mMapFragment;
    private static final String MAP_FRAGMENT_TAG = "map";
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try{
            setContentView(R.layout.map_activity);
            mMapFragment = (SupportMapFragment) getSupportFragmentManager()
                    .findFragmentByTag(MAP_FRAGMENT_TAG);
            if(mMapFragment==null)
                addMapFragment();
            setUpMapIfNeeded();

        }
        catch(Exception ex){
            System.err.println("Exception: " + ex.getMessage());

        }

    }

    private void addMapFragment(){
        try{

            GoogleMapOptions options = new GoogleMapOptions();
            options.mapType(GoogleMap.MAP_TYPE_NORMAL)
                    .zoomControlsEnabled(true) ;

            mMapFragment =  SupportMapFragment.newInstance(options);
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            transaction.add(R.id.fragment_map_content, mMapFragment,MAP_FRAGMENT_TAG);
            //transaction.addToBackStack(null);
            transaction.commit();
        }
        catch(Exception ex){
            System.err.println("Exception: " + ex.getMessage());
        }

    }

private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the map.
        if (mMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            mMap =  mMapFragment.getMap(); ***//ALWAYS RETUN NULL***
            //mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))

            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                setUpMap();
            }
        }
    }

在onResume()中调用SetupMapiFneed,如下所示

@Override
protected void onResume() {
    super.onResume();

    // In case Google Play services has since become available.
    setUpMapIfNeeded();
}

获取私有谷歌地图mMap;要工作,您是否导入了其他库或包?