0

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.

  1. Is there a way to set a timeout for GPS search (detect indoors situation)?
  2. 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?
  3. 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!

  • i think you will have to ask the user to set it to BALANCED_POWER, programmatically making the requests would not change the device setting if it is already set to HIGH_ACCURACY, check [prompting user about location settings](http://stackoverflow.com/questions/28759454/enabling-location-with-mode-high-accuracy-or-battery-saving-without-user-needing) – Pararth Oct 14 '15 at 12:34
  • for GPS search scenario, you can add a timer for obtaining the location with only GPS and if its not obtained in a specific duration, arrange the callback according to what you want. ALSO, FusedLocationProviderApi works well, i suggest not to revert to the old one – Pararth Oct 14 '15 at 12:37
  • Thing is I don't mind using the GPS. What I do mind is wasting 30% of the battery trying to get a GPS fix indoors, especially if I didn't explicitly ask for it. @user2450263 – Nemanja Maksimovic Oct 14 '15 at 12:38
  • yeah then what you can do is set a short interval for the timer while trying to obtain the location from GPS, 9/10 scenarios, where there is no line-of-sight issue, you will get the location within seconds – Pararth Oct 14 '15 at 12:40
  • And how would I tell FusedLocationProviderApi that I do, or do not want GPS? I still don't trust PRIORITY_BALANCED_POWER_ACCURACY to guarantee prevent GPS being turned on. – Nemanja Maksimovic Oct 14 '15 at 12:42
  • Hmm, 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. – Nemanja Maksimovic Oct 14 '15 at 12:44

0 Answers0