Thursday, December 27, 2012

[android-developers] Location Listener Question

Yes, I know that there are a million resources out there that deal with
the best way to obtain a location and I did google quite a bit before
making this post. If someone can point me to something I missed, I'd
appreciate it.

Having said this my needs (for the purpose of this question) are quite
simple: Once an hour I want to obtain my location from the Network.

Here is what I did:

1) Created an alarm to trigger once an hour.
2) Invoke LocationManager.removeUpdates().
3) Request location updates, specifying a listener. I am specifying
minTime and minDistance values of 0.
4) As soon as the listener is fired, save the location and invoke
LocationManager.removeUpdates().

I see a few issues with this:

1) I am shutting down the listener as soon as I get an update. But I
should probably wait for a few updates in order to allow it to zero
in on the location (I already have code that figures out best
location from those available).

2) The listener does not seem to fire consistently. My location is not
always getting updated and it looks like the listener is simply not
getting called.

I ran some tests where I never remove updates. With the above settings
my listener is being called appx every 45 seconds. So I know that my
overall code is written correctly.

What is the canonical "best" way to do what I want? Should I collect
updates in my Listener for, say, 2 minutes and use an alarm (set to
trigger two minutes after my hourly alarm is triggered) to remove
updates? Is there a better way to solve this problem?

--
Jake Colman -- Android Tinkerer

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment