What is the best way to wait for a GPS location fix?
Posted
by qtips
on Stack Overflow
See other posts from Stack Overflow
or by qtips
Published on 2010-04-06T14:18:09Z
Indexed on
2010/04/06
16:13 UTC
Read the original article
Hit count: 198
android
Hi,
Using my Android application, when a user does a certain action, a background service is started that fetches the current GPS location and saves it in a database in addition of doing some other stuff. In that service, I use the requestLocationUpdates()
from the LocationManager
class and wait until the onLocationChanged()
of my LocationListener
(which is implemented by the service) is fired. But what is the best way to wait for the onLocationChanged
to fire? Should I simply poll on a variable and wait until it is set? Any tips?
Note: I cannot simply write to the database in the onLocationChanged()
because of some other stuff.
EDIT: To clearfy my situation, I can present an example similar to my case: Let's say user pushes a button and a method myMethod is fired which will return some object. Then, in this myMethod I will register for location updates from the GPS (using requestLocationChanged) and in addition wait for the users location and use it for something. In other words, myMethod cannot return before the location is present. I don't know how I can use onLocationChanged in this case.
© Stack Overflow or respective owner