I create a LocationListener and register it with the LocationManager to receive changes in the location, but a problem arises: no answers come to the listener's methods! Totally! Here is the creation code:

  LocationListener listener = new LocationListener() { @Override public void onLocationChanged(Location location) { if (lastLocation == null) { lastLocation = location; } distanceInMeters += location.distanceTo(lastLocation); lastLocation = location; Log.i(TAG, "LocationChanged"); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { Log.i(TAG, "StatusChanged"); } @Override public void onProviderEnabled(String provider) { Log.i(TAG, "ProviderEnabled"); } @Override public void onProviderDisabled(String provider) { Log.i(TAG, "ProviderDisabled"); } }; LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Log.i(TAG, "FCK..."); return; } locationManager.requestLocationUpdates(locationManager.GPS_PROVIDER, 1000, 1, listener); 

Why the listener does not work and how to fix it?

PS GPS - turned on.

  • you debazili, whether reaches call requestLocationUpdates? - Yury Pashkov
  • @YuryPashkov, fortunately (or unfortunately) - it comes. - user189127
  • By code, everything seems to be correct. On another device, we did not try to test, just gps "warm up" is necessary, so that the coordinates start to come, sometimes it can take 5 minutes. Is the manifest all right too? - Yury Pashkov
  • @YuryPashkov, I'll start now and wait (although what nafig 5 minutes should work right away, this is a hard jamb from the developers), in the manifest permission is <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> , and the other go now no ... - user189127
  • @YuryPashkov, wow! The answer has come! True onProviderDisabled ... - user189127

1 answer 1

For GPS, add permission <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> ACCESS_COARSE_LOCATION - on cell towers ACCESS_FINE_LOCATION - gps

  • Earned! I'm going to read about the resolution, I’m not talking about it in the book ... - user189127
  • And you are not confused? Can coarse on towers? It only worked with him for me, and I'm sitting with a mob. the internet. Yes, and Google docks write that coarse is an approximate location (which, in the sense, should be typical of simok), and fine - exact. This is somehow not logical, and the names are strange (when translating keywords I didn’t get a sense without documentation). - user189127