更改minTime的GPS动态LocationListener的 [英] Change minTime for GPS LocationListener dynamically
问题描述
这是我写的应用程序使用GPS定位管理器服务requestLocationUpdates(),但我希望能够在整个程序中改变最短时间和最小距离参数。我初始化创建时的位置监听器,但我无法弄清楚如何改变这些参数,甚至找出是否有可能做到这一点。这样做的主要目的是为了保护电池寿命,当程序不需要定期位置更新。非常感谢您的帮助!
-dom
The app that I'm writing uses the GPS location manager service requestLocationUpdates() but I would like to be able to change the min Time and min Distance parameters throughout the program. I initialize the location listener on creation but I can't figure out how to change these parameters or even find out if it's possible to do that. The main purpose for this would be to conserve battery life when the program doesn't need regular position updates. Thanks so much for your help! -Dom
推荐答案
我不知道这是否是正确的,但面临着同样的问题,我偶尔会删除LocationListener的,再后来用不同的刷新间隔添加回
I'm not sure if this is correct, but faced with the same problem, I occasionally remove the LocationListener and then later add it back with a different refresh interval:
if (locationManager != null && locationListener != null) {
locationManager.removeUpdates(locationListener);
}
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, refreshInterval, 50, locationListener);
这篇关于更改minTime的GPS动态LocationListener的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!