动态更改 GPS LocationListener 的 minTime [英] Change minTime for GPS LocationListener dynamically

查看:17
本文介绍了动态更改 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆