Reputation: 611
My app find out current location using GPS
. It is working fine in outdoor. But where GPS
is not available or poor it is trying to get update again and again and it drains battery. So i want to stop update when GPS
is poor or unavailable. You may suggest to use
lm.removeUpdates(locationlistenerforGPS);
It is working fine when GPS
is available not in indoor. I like to stop update when GPS
is poor or unavailable.
my code is
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener locationlistenerforGPS = new mylocationlistenerGPS();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationlistenerforGPS);
My locationlistenerGPS() function is
private class mylocationlistenerGPS implements LocationListener {
@Override
public void onLocationChanged(Location location) {
counterGPS++;
if (location != null) {
Log.d("LOCATION CHANGED", location.getLatitude() + " ");
Log.d("LOCATION CHANGED", location.getLongitude() + " ");
Toast.makeText(LocationActivity.this,"latitude: "+
location.getLatitude() + "longitude: " + location.getLongitude()
+ " Provider:" + location.getProvider() + " Accuracy:" + location.getAccuracy(),
Toast.LENGTH_LONG).show();
}
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
Thank you very much for any kind of assistance.
Upvotes: 2
Views: 717
Reputation: 13247
Don't use minTime
and minDistance
set to zero in requestLocationUpdates()
. See requestLocationUpdates() documentation.
Bundle extras in onStatusChanged() may include satellites - the number of satellites used to derive the fix, this way you can define poor signal or you can use NmeaListener if you need additional information from GPS.
Upvotes: 1