如何在MainActivity类中使用getSupportFragmentManager()来扩展MapActivity

时间:2014-04-15 09:08:47

标签: java android google-maps android-fragmentactivity mapactivity

我正在尝试在MainActivity类中使用getSupportFragmentManager(),它扩展了MapActivity但我收到了以下错误,我无法解决。

"方法getSupportFragmentManager()未定义类型MainActivity"

之前我正在扩展FragmentActivity,它工作正常,但现在我想添加mapoverlay,这就是我扩展MapActivity的原因。

以下是相关代码的部分

public class MainActivity extends MapActivity {

  GoogleMap googleMap;
  MarkerOptions markerOptions;
  LatLng latLng;
  Geocoder geoCoder;
  EditText editText;
  GeoPoint p;
  MapController controller;
  MapView mapView;
  Button btnSearch;  

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

       int status = GooglePlayServicesUtil
                .isGooglePlayServicesAvailable(getBaseContext());

    if (status != ConnectionResult.SUCCESS) {
        // Google Play Services are not available

        int requestCode = 10;
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this,
                requestCode);
        dialog.show();

    } 

    else {

        // Getting reference to the SupportMapFragment
        SupportMapFragment fragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        // Getting Google Map
        googleMap = fragment.getMap();

       MapView mapView = (MapView) findViewById(R.id.mapView);

       addListenerOnButton();
    }

}

0 个答案:

没有答案