Adri
Adri

Reputation: 385

How stop gps if the position is not yet fixed?

In my android application I active the fix position with gps:

mLManager.requestLocationUpdates (LocationManager.GPS_PROVIDER, 30000, 0, mLListener);

so that every 30 seconds the GPS is active and looking for the position. What I would like is this: the gps is activated for the n-th time, and as I walked into a building fails to fix my position so he seeks the position indefinitely. Can I stop it if the position is not fixed in 60 seconds? how can I do that? Thanks in advance!

Upvotes: 0

Views: 74

Answers (1)

Bigflow
Bigflow

Reputation: 3666

public boolean getLocation(Context context) {
         mLManager.requestLocationUpdates (LocationManager.GPS_PROVIDER, 30000, 0,mLListener);
         timer1=new Timer();
         timer1.schedule(new GetLastLocation(), 60000);

         return true;
}

LocationListener mLListener = new LocationListener() {
         public void onLocationChanged(Location location) {
         timer1.cancel();
         }
};

class GetLastLocation extends TimerTask {
       @Override
        public void run() {
        }
}

It looks for a location, if it didn't found any location, and the 60 secs expires, then the timer will and you can execute an action. if it does find a location, it will cancel the timer.

Upvotes: 1

Related Questions