Ayman Emad
Ayman Emad

Reputation: 113

the method getController() is undefined for the type MapView

i want to detect the user location by google maps and follow a google tutorial but there is error in the method(getController) in line 6 , the error details the method getController() is undefined for the type MapView

private GoogleMap map;

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

    MapView view = (MapView) findViewById(R.id.map);
    final MapController control = view.getController();
    LocationManager Manager = (LocationManager) this
            .getSystemService(Context.LOCATION_SERVICE);

    LocationListener listener = new LocationListener() {

        public void onStatusChanged(String provider, int status,
                Bundle extras) {
            // TODO Auto-generated method stub

        }

        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onLocationChanged(Location location) {

            control.setCenter(new GeoPoint((int) location.getLatitude(),
                    (int) location.getLongitude()));
        }
    };

    Manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
            listener);

}

}

Upvotes: 2

Views: 2233

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007464

There are two Maps APIs for Android.

One is Maps V1. Its classes are in the com.google.android.maps package. Maps V1 has been deprecated and should not be used for new apps.

The other is Maps V2. Its classes are in the com.google.android.gms.maps package.

You are attempting to blend both. This will not work.

I would recommend that you spend some time reading the documentation for Maps V2 and focusing on that, removing all references to Maps V1 classes from your code.

Upvotes: 1

Related Questions