0

I am developing an android application wherein I need the user location updates pretty frequently. Say 2 times a minute.

Earlier I had been using Google Play Service's "Fused location service" but the location updates were not received as requested. The location updates got stuck for sometime, the interval between updates jumped to 10min or so.Sometimes even if I put my priority to "PRIORITY_HIGH_ACCURACY" the same happened.

I then went back to the old "Location Manager" and when I used the "NETWORK_PROVIDER", I noticed that the location updates got stuck due to this provider. Also the GPS does not get activated immediately, it takes some time. I am trying to build my custom fused location provider. How can I efficiently switch between providers, without getting lags on location updates.

I want to know what are the best practices for getting location updates regularly, all the time, be it either NW, GPS or both. Like it should work for an application where location updates getting stuck cannot be afforded.

Battery drain is not an issue for me right now.I am aware of all the supporting docs that Google provides regarding location access.

Any help would be much appreciated.

Thankyou !

geekoraul
  • 2,623
  • 2
  • 21
  • 33

1 Answers1

1

FusedLocationProvider really is the best option for obtaining locations at the moment, because it uses a lot more than just GPS or Network data to obtain location fixes. I have experienced issues regarding intervals being missed as well, but ultimately this is something down to luck depending on availability of GPS, Network, etc. etc.

My favourite usage of FusedLocationProvider so far is in conjunction with the AlarmManager class: Basically, the idea is to start location tracking at intervals specified by the Alarm Manager (this can be set to every 30 seconds such as in your case). Once the interval is hit, the location provider is to obtain a location fix as soon as possible (so in the setInterval method or whatever it's called, the parameter is a 0). This way, you can avoid having to wait another 30 seconds for a new location, instead having the location tracker attempt to provide a location as soon as possible after the interval specified by the Alarm Manager is hit.

By the way, when making custom location tracking wrappers, be careful of using the .getLastKnownLocation() method as it only uses cached locations - you could end up sending the same location to the user every 30 seconds.

Good luck!

SJunejo
  • 71
  • 1
  • 8
  • What else does FusedLocationProvider use, other than the NW/GPS ? Can you throw some light on it ? As far as I know it uses GPS, NW and a 'Passive provider' that listens for location updates that are triggered by other applications. And yes I am using the alarm manager based approach as you mentioned – geekoraul Mar 12 '14 at 23:18
  • It also uses celltower data, as well as internal sensors to aid in providing a more accurate location. I guess *technically* the NETWORK_PROVIDER option through the old LocationManager class is supposed to use celltower data as well - but in practice, due to the lower accuracy readings, updates won't happen as regularly, and lack of Wi-Fi/3G really lets it down. – SJunejo Mar 12 '14 at 23:26
  • According to the documentation of NETWORK_PROVIDER of LocationManager class "This provider determines location based on availability of cell tower and WiFi access points. Results are retrieved by means of a network lookup". It uses all N/W sources. In FusedLocationProvider, if you have your wifi on and you step out of a wifi NW, the location updates get stuck. Whereas if you operate updates with the LocationManager and NW provider ONLY, it does not get stuck – geekoraul Mar 12 '14 at 23:30
  • Really? That's never happened to me with FLP before. Sounds like a pretty glaring bug if that's the case. – SJunejo Mar 12 '14 at 23:39