我有完全一样的问题,我的应用程序。我使用了一个在启动时初始化的计时器:
serviceHandler = new Handler(); serviceHandler.postDelayed(new RunTask(),1000L);
这将运行locupdate并每秒添加一个计数器。
class RunTask implements Runnable {
public void run() {
++counter;
locupdate(0,0);
serviceHandler.postDelayed(this, 1000L);
}
}
这是上面使用的locupdate函数。请注意,mlocManager是全局定义为LocationManager的。
public void locupdate(int minTime, float minDistance) {
mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mlocListener = new MyLocationListener();
if (mlocListener != null && mlocManager != null) {
mlocManager.removeUpdates(mlocListener);
}
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
minTime, minDistance, mlocListener);
}
最后一件事。在LocationListener的onLocationChanged方法的结尾,我删除了5个位置修复后的更新:
mlocManager.removeUpdates(mlocListener);
这与requestSingleUpdate()类似,但我觉得它更灵活。希望这可以帮助!
谢谢你给我答复,但我不能得到你的答案..请你给我一些源代码 – kinju 2011-04-19 05:51:30