1. Download our Official Android App: Forums for Android!

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

Discussion in 'Android Development' started by ac4android, Jul 25, 2016.

  1. ac4android

    ac4android Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    53
    Posts:
    198
    Joined:
    Nov 3, 2015

    Nov 3, 2015
    198
    29
    53
    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 (Text):
    1.  
    2.   private void runLocTimer() {
    3.  
    4.   final TextView sysmsgview = (TextView) findViewById(R.id.sysmsg_view);
    5.   final TextView latitudeview = (TextView) findViewById(R.id.latitude_view);
    6.   final TextView longitudeview = (TextView) findViewById(R.id.longitude_view);
    7.   final TextView accuracyview = (TextView) findViewById(R.id.accuracy_view);
    8.  
    9.   locationmanager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
    10.   // get GPS status
    11.   gpsEnabled = locationmanager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    12.   // get network statuis
    13.   networkEnabled = locationmanager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    14.   //
    15.   final Handler handler = new Handler();
    16.   handler.post(new Runnable() {
    17.   @Override
    18.   public void run() {
    19.   //TODO
    20.   String slat = String.valueOf(dd);
    21.   sysmsgview.setText(slat);
    22.   latitudeview.setText(latitude);
    23.   longitudeview.setText(longitude);
    24.   accuracyview.setText(accuracy);
    25.  
    26.   if(running){
    27.   dd++;
    28.   if (gpsEnabled){
    29.   if (location == null) {
    30.   locationmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
    31.   if (locationmanager != null) {
    32.   location = locationmanager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    33.   if (location != null) {
    34.   latitude = String.valueOf(location.getLatitude());
    35.   longitude = String.valueOf(location.getLongitude());
    36.   accuracy = String.valueOf(location.getAccuracy());
    37.   }
    38.   }
    39.   }
    40.   }
    41.   }
    42.   handler.postDelayed(this, 1000);
    43.   }
    44.   });
    45.   }
    46.  
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #17
    Points:
    1,488
    Posts:
    6,715
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    6,715
    9,445
    1,488
    Male
    Software developer
    South West of England
  3. ac4android

    ac4android Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    53
    Posts:
    198
    Joined:
    Nov 3, 2015

    Nov 3, 2015
    198
    29
    53
    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 (Text):
    1.  
    2.   private void runLocTimer() {
    3.   final TextView sysmsgview = (TextView) findViewById(R.id.sysmsg_view);
    4.   final TextView latitudeview = (TextView) findViewById(R.id.latitude_view);
    5.   final TextView longitudeview = (TextView) findViewById(R.id.longitude_view);
    6.   final TextView accuracyview = (TextView) findViewById(R.id.accuracy_view);
    7.   // prime the locationmanager and get the first lot of data
    8.   locationlistener = new MyLocationListener();
    9.   locationmanager = (LocationManager) getSystemService(LOCATION_SERVICE);
    10.   // mylocation = locationmanager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    11.   locationmanager.requestLocationUpdates(
    12.   LocationManager.GPS_PROVIDER, 1000, 5, new LocationListener() {
    13. [INDENT]  @Override
    14.   public void onLocationChanged(Location location) {
    15.   // get the new location data
    16.   latitude = String.valueOf(mylocation.getLatitude());
    17.   Toast.makeText(getApplicationContext(), "Latitude->"+latitude, Toast.LENGTH_LONG).show(); // returns NULL! I am getting more than my fair share of NULLs :mad:
    18.   //dlongitude = mylocation.getLongitude();
    19.   //faccuracy = mylocation.getAccuracy();[/INDENT]
    20.   }
    21.   @Override
    22.   public void onProviderDisabled(String provider) {
    23.   // TODO Auto-generated method stub
    24.   }
    25.   @Override
    26.   public void onProviderEnabled(String provider) {
    27.   // TODO Auto-generated method stub
    28.   }
    29.   @Override
    30.   public void onStatusChanged(String provider, int status, Bundle extras) {
    31.   // TODO Auto-generated method stub
    32.   }
    33.   });
    34.   final Handler handler = new Handler();
    35. ...
    36.  
     
    #3 ac4android, Jul 27, 2016
    Last edited: Jul 27, 2016
  4. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #17
    Points:
    1,488
    Posts:
    6,715
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    6,715
    9,445
    1,488
    Male
    Software developer
    South West of England
    ^--- That should do the job
     

Share This Page

Loading...