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 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.
精彩评论