Change minTime for GPS LocationListener dynamically(动态更改 GPS LocationListener 的 minTime)
问题描述
我正在编写的应用程序使用 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);
这篇关于动态更改 GPS LocationListener 的 minTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:动态更改 GPS LocationListener 的 minTime
基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
