elty123
elty123

Reputation: 277

Obtaining GPS data every 1 second

I am wondering if there is a way to gather GPS location data every second? My understanding is is the locationListener is only called when the location is changed. I have a thread running every second in this manner:

private void startTimer() {
    _mHandler.removeCallbacks(mUpdateTimeTask);
    _mHandler.postDelayed(mUpdateTimeTask, 1000);   
}

private Runnable mUpdateTimeTask = new Runnable() {
    public void run() {
        _mHandler.postDelayed(this, _interval);

         // work
    }
};

Upvotes: 0

Views: 1011

Answers (2)

MByD
MByD

Reputation: 137442

Why do you need to query the location every second? register a listener and set up synchronized members to hold the last location and query them in your 1-second-interval thread.

Upvotes: 1

Kevin Qiu
Kevin Qiu

Reputation: 1626

LocationManager

You can set the mintime to 1000ms for location updates in the method requestLocationUpdates.

Upvotes: 1

Related Questions