• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Inner Class Cannot resolve requestLocationUpdates(...) ?

ac4android

Well-Known Member
My handler has an inner class that calls the requestLocationUpdates() method.

It has the following syntax error:
"Cannot resolve method requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,this);

But it recognises both the getLastKnownLocatoin() method and my locationmanager !?!

Where have I gone wrong and how do I fix it?

The flow of logic is quite bad at the moment, but I just want to get it working first.

Code:
  private void runLocTimer() {

  final TextView sysmsgview = (TextView) findViewById(R.id.sysmsg_view);
  final TextView latitudeview = (TextView) findViewById(R.id.latitude_view);
  final TextView longitudeview = (TextView) findViewById(R.id.longitude_view);
  final TextView accuracyview = (TextView) findViewById(R.id.accuracy_view);

  locationmanager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
  // get GPS status
  gpsEnabled = locationmanager.isProviderEnabled(LocationManager.GPS_PROVIDER);
  // get network statuis
  networkEnabled = locationmanager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
  //
  final Handler handler = new Handler();
  handler.post(new Runnable() {
  @Override
  public void run() {
  //TODO
  String slat = String.valueOf(dd);
  sysmsgview.setText(slat);
  latitudeview.setText(latitude);
  longitudeview.setText(longitude);
  accuracyview.setText(accuracy);

  if(running){
  dd++;
  if (gpsEnabled){
  if (location == null) {
  locationmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
  if (locationmanager != null) {
  location = locationmanager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  if (location != null) {
  latitude = String.valueOf(location.getLatitude());
  longitude = String.valueOf(location.getLongitude());
  accuracy = String.valueOf(location.getAccuracy());
  }
  }
  }
  }
  }
  handler.postDelayed(this, 1000);
  }
  });
  }
 
I created an inner class for the LocationListener, maybe that's the issue.
Maybe if I create a private class MyLocationListener {}, it'll work...

Code:
  private void runLocTimer() {
  final TextView sysmsgview = (TextView) findViewById(R.id.sysmsg_view);
  final TextView latitudeview = (TextView) findViewById(R.id.latitude_view);
  final TextView longitudeview = (TextView) findViewById(R.id.longitude_view);
  final TextView accuracyview = (TextView) findViewById(R.id.accuracy_view);
  // prime the locationmanager and get the first lot of data
  locationlistener = new MyLocationListener();
  locationmanager = (LocationManager) getSystemService(LOCATION_SERVICE);
  // mylocation = locationmanager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  locationmanager.requestLocationUpdates(
  LocationManager.GPS_PROVIDER, 1000, 5, new LocationListener() {
[INDENT]  @Override
  public void onLocationChanged(Location location) {
  // get the new location data
  latitude = String.valueOf(mylocation.getLatitude());
  Toast.makeText(getApplicationContext(), "Latitude->"+latitude, Toast.LENGTH_LONG).show(); // returns NULL! I am getting more than my fair share of NULLs :mad:
  //dlongitude = mylocation.getLongitude();
  //faccuracy = mylocation.getAccuracy();[/INDENT]
  }
  @Override
  public void onProviderDisabled(String provider) {
  // TODO Auto-generated method stub
  }
  @Override
  public void onProviderEnabled(String provider) {
  // TODO Auto-generated method stub
  }
  @Override
  public void onStatusChanged(String provider, int status, Bundle extras) {
  // TODO Auto-generated method stub
  }
  });
  final Handler handler = new Handler();
...
 
Last edited:
Back
Top Bottom