开发者

Obtaining GPS data every 1 second

开发者 https://www.devze.com 2023-03-25 16:57 出处:网络
I am wondering if there is a way to gather GPS location data every second?My understanding is is the locationListener is only c开发者_Go百科alled when the location is changed.I have a thread running e

I am wondering if there is a way to gather GPS location data every second? My understanding is is the locationListener is only c开发者_Go百科alled 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
    }
};


LocationManager

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消