LocationManager versus FusedLocationProvider - android

Currently we use LocationManager to get GPS updates every few seconds, we use it for high accuracy updates.
Besides, we also want to get location coordinates every 5 minutes irrespective of GPS state (turned on/off), we really ignore accuracy of location in this scenario. We want to use FusedLocationProvider for this operation.
Can both locationmanager and fusedlocationprovider co-exist in the same app; if so, are there any reliability issues?

Related

FusedLocationProviderApi, PRIORITY_BALANCED_POWER_ACCURACY and GPS usage

I'm creating an app which tracks the location through FusedLocationProviderApi in a Foreground Service.
When I create LocationRequest with PRIORITY_BALANCED_POWER_ACCURACY and start listening for location updates, to my surprise GPS fires up ( Location in the phone settings is set to High Accuracy). I get the location almost immediately (through wifi/cell sources I guess), but as I'm indoors I can't get a GPS fix and it just keeps on trying without end...
Even though I didn't ask for PRIORITY_HIGH_ACCURACY I get hit with significant battery drain and get blamed for using GPS for several minutes.
Is there a way to set a timeout for GPS search (detect indoors situation)?
Is it possible to get a decent location using FusedLocationProviderApi without automatically triggering GPS or do I have to revert to the old location API?
Do I have to resort to limiting each LocationRequest to couple of minutes (setExpirationDuration) and create a new one to prevent the GPS battery drain?
[EDIT]: I think I might have found an another culprit. On a map tab in the app I have set setMyLocationEnabled(true), and this seems to be causing the GPS to flare up. I will experiment a bit more and post the results. Still I'm interested in how the location manager decides that enough is enough when it comes to GPS fix attempt.
Thanks in advance!

best way to save battery with gps location

I have a background thread that needs to get the GPS location every 1 hour.
What would be the best way to do this?
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000*60*60,0, this);
have the thread sleep for a hour and then register for updates and after receiving the location will
removeUpdates(...)
And what is the difference between LocationManager.NETWORK_PROVIDER and LocationManager.GPS_PROVIDER.
Instead of using LocationManager use Location API . It provides much better accuracy and eats less power and its faster at getting the location.
Your second option from point of GPS consumption is the best one. But instead letting the thread to sleep for an hour I would use a timer with period = 1 hour. If you cannot garuantee that your app will stay active for that hour, you want to store the last reveived location time. Once your app wakes up next time you check the system time stamp and compare it to your last location time on permanent storage. If the hour was exceeded you immeadetly demand a location, and later continue with timers. If the hour has not yet passed, the you calculate the time difference and start a timer with initial delay of that difference, and period of 1hour.
But thi sanswr is not dealing how to keep your app alive, it tells you from point of power consumption that is is better to enable GPS only for that short moment you need it.
Getting a GPS location will need from 20-40s.
You should set highest accuracy. (GPS)
After enabling GPS and receiving a valid location, check the horicontal accuracy.
Leave GPS enabled until the accuracy reach the desired threshold (e.g <15m).
Then disable GPS.
With that solution GPS needs only power for about a minute every hour, which is negligible low.
You can use Criteria for that, customize it according to your need.
A class indicating the application criteria for selecting a location provider. Providers maybe ordered according to accuracy, power usage, ability to report altitude, speed, and bearing, and monetary cost.
code sample :
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);
Have a look at how to use locationmanager , how to specify Criteria and how getBestProvider method works for reference

Variation in GPS data being at same location

In my application, I have calculated speed based on GPS locations.
As GPS receiver can have different coordinates even being on the same location, my app is recording speed even when phone is on my desk.
I need to avoid GPS data if I am receiving it being on same location.
I am thinking of adding some logic based on “bearing”, so that I can decide if the phone is actually moving or it’s receiving jumpy location data from any direction.
Before that I would like to know is there any other way to avoid this kind of data?
AS per the Javadoc for the method request public void requestLocationUpdates (long minTime, float minDistance, Criteria criteria, PendingIntent intent) found here
minTime minimum time interval between location updates, in
milliseconds minDistance
minimum distance between location updates, in
meters
so you can use minDistance parameter to avoid getting update for very short distances...
After working on many methods I programmed it with bearing.
I am getting speed based on last 5 locations. I added Logic to check bearing for each location with next location and if all bearing have larger difference, I assumed locations are being received from random directions and so the device is not actually moving.
And it worked great for me :)

Android GPS takes too much time to get the location

In my app the GPS takes too much time to get the location.
How can I use GPS from GPS_SATELLITES and GPS _NETWORK_PROVIDERS simultaneously in the same context and get the value of the recent GPS?
Keep track of a Location object that is your current location. Request location updates from both
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
LOCATION_UPDATE_FREQUENCY, LOCATION_UPDATE_MIN_DISTANCE,
gpsListener);
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, LOCATION_UPDATE_FREQUENCY,
LOCATION_UPDATE_MIN_DISTANCE, networkListener);
then when you get a response in onLocationChanged of either listener, either simply replace the Location variable you stored or replace it only if it is X seconds more recent, X% more accurate, X meters distant from your last reading, etc.
You can also use LocationManager.getAllProviders(), then call LocationManager.getLastKnownLocation(provider) to retrieve the last location each available provider found the last time it was called. This way, if another app used the GPS a minute ago, you can just go ahead and trust that they user hasn't made it that far away without hunting for satellites all over again.

Android getting GPS Location on a fixed interval, how much impact on Battery and what goes in the background If we are getting location per hour

When getting GPS location on a fixed interval (say per hour), does this drain the battery every hour, every minute or only when either actually getting the location each hour or updating the location. I'm eager to know what goes on in the background.
Here is what this reference says
"Background services should be careful about setting a sufficiently high minTime so that the device doesn't consume too much power by keeping the GPS or wireless radios on all the time. In particular, values under 60000ms are not recommended. "
So I'm hoping that when the location is changed, or after minTime, the GPS radios are on, and after getting location, the GPS radios are off
Can anyone confirm this to be true?
According to reference we can decide that expensive battery using happens when GPS engine try to get new location and we can control freqency of this using method public void requestLocationUpdates (long minTime, float minDistance, Criteria criteria, PendingIntent intent)
Battery consumed is at its peak at the time when location manager tries to pinpoint your location(you can observe GPS icon blinking on status bar at that time) and this happens once in an hour in your case.. So GPS is automatically turned to "not available" state once you get a location until your next hour is reached..
And the line "In particular, values under 60000ms are not recommended" is said because it takes some time for GPS to point out your location, typically a minute maybe depending on your satellite strength.. So if your minTime is set to less than a minute(60000ms) its like your GPS is almost on for all the time..
Read here for more details

Categories

Resources