Eclipse在MapFragment.getMap()行上显示错误

时间:2014-02-13 15:39:40

标签: android

Eclipse在MapFragment.getMap()行显示错误;这是我的源代码:

MapActivity:

public class MapActivity extends BaseActivity {

    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // replace content_menu fragment with map fragment
        FragmentTransaction fragTans = getFragmentManager().beginTransaction();
        fragTans.replace(R.id.content_frame, new MapFragment());
        fragTans.commit();
    }
}

MapFragment

public class MapFragment extends Fragment {

    @SuppressWarnings("unchecked")
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Map setup 
    View mapView = inflater.inflate(R.layout.map_layout, null);

        // Eclipse show me that getMap is not exist here 
    GoogleMap mapGoogle = ((MapFragment)getFragmentManager().findFragmentById(R.id.map_view)).getMap();

    // ... customize my map , add marker ....
        return mapView;
    }
}

最好的问候

1 个答案:

答案 0 :(得分:0)

view = inflater.inflate(R.layout.map_tab_fragment, container, false);
SupportMapFragment fm = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.map);
map = fm.getMap();