Reputation: 44230
with android and using GPS as a location provider, how can I tell it to stop looking for a GPS lock after a specified number of seconds and simply resort to using the last known location instead?
I am currently doing it the other way around, where I get the lask known location first, and then let the request update function run. My problem with this is that the GPS will sometimes NEVER get a fix, but it doesn't stop trying to get a fix. Very annoying issue to me (and probably to some users)
suggestions?
Upvotes: 0
Views: 681
Reputation: 6899
May be you can use a Timer for this. you can follow below steps.
Before registering the Location listener , define and schedule a timer with the above TimerTask and a delay say 60000 miliseconds (Your timeout period). Use the below method for schedule.
public void schedule (TimerTask task, long delay)
e.g. timer1.schedule(timerTask,60000)
This should stop the location listener after 60 seconds as you are unregistering it in the timertask. Hope it will help.
Upvotes: 2