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


基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01