Location service
Closed this issue · 7 comments
This app needs location data frequently. It should (in my opinion) be implemented as a service: http://developer.android.com/guide/components/services.html
Do we need Google Play library in this? Does it provide any additional value or should we just ignore it?
I think a Service is what we want. I don't know whether it should run continuously, be run periodically by the Alarm Manager, or something else.
In this case I'm leaning towards using the Android location services instead of Google Play, because
- it's simpler to set up and doesn't lock us into the Google Play platform, but also because
- it might be nice to have the finer-grained access to data from individual location providers
I think we ought to store every location sample in the database, including some subset of the data of an android.location.Location. How about:
- latitude, longitude
- accuracy
- provider
- time (probably just UTC time, though maybe elapsed real-time; see the android.os.SystemClock documentation)
I found some discussion on AlarmManager-solution. The downside of it is that it is not 100% sure if the gps has "warmed up" so the location get stored on every system call.
Some guy had therefore made this: https://github.com/commonsguy/cwac-locpoll
I planned to try that out and see if it works. Otherwise I try that basic AlarmManager approach.
That looks worth a try. A couple other things I noticed that were mentioned there:
- https://github.com/alexbirkett/cwac-locpoll is a fork with perhaps some useful features
- the Google Play location services actually have good controls for getting periodic updates, using LocationRequest
(For what it's worth, what I had been thinking of was the somewhat more complex:
- wake up
- check all location providers and see whether any of them has an updated location since last time we checked
- if so, pick the one with the best accuracy
- if we haven't had any updates in long enough, actually request a location update ourselves
But periodic location updates is apparently a solved problem, and I guess there's nothing special about our use that would really justify doing it from scratch.)
Okay. I try to do it with https://github.com/alexbirkett/cwac-locpoll, because fork is always better than the original.
(resolved by the work in #4)