信号好的情况下GPS更新间隔越快?
我试图限制我的程序每 10 秒更新一次位置,而不是不断更新,以减少电池消耗。当我在室内调试且信号较弱(即 GPS 图标闪烁)时,此方法工作正常,但如果手机得到正确修复(即 GPS 图标是静态的),更新间隔会增加到大约一秒。
我知道代码 mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateInterval*1000, 0, this);
不会强制 GPS 完全按照给定的时间间隔进行更新,但在我看来它应该'它取决于信号的强度并波动很大。
有什么想法吗?
更新:见评论
I'm trying to limit my program to take location updates every 10 seconds instead of constant updates in order to reduce battery drain. This works fine when i'm debugging indoors and the signal is weak (i.e. the GPS icon flashes), but if the phone gets a proper fix (i.e. the GPS icon is static) the update interval increases to roughly a second.
I know that the code mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateInterval*1000, 0, this);
will not force the GPS to take updates exactly at the given interval, but in my opinion it shouldn't depend on the strength of the signal and fluctuate that much.
Any ideas?
UPDATE: see comment
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑 GPS 无线电的工作方式要么连接到 GPS 卫星,要么不连接。连接后,Android SDK 会按照 GPS 硬件提供的更新频率向您发送更新。当它没有完整的 GPS 连接时,它会根据您的请求发送 AGPS 更新。
如果您只想每 10 秒更新一次,则应将最后接收到的
Location
的时间值保存在监听器中,并且当您收到新的Location
时,根据旧值;如果它太频繁,请忽略它(或者做一些更聪明的事情,例如检查准确性和替换旧值等)。I suspect that the GPS radio works in a manner where either it's connected to GPS satellites or it's not. When it's connected, the Android SDK sends you updates as frequently as they're available from the GPS hardware. When it doesn't have a full GPS connection it falls back to sending AGPS updates according to what you've requested.
If you only want updates every 10 seconds, you should save the last received
Location
's time value in your listener, and when you receive a newLocation
check its time against the old value; ignore it if it's too frequent (or do something smarter like checking the accuracy and replacing the old value, etc).也许它运行得慢是因为你正在调试,但不是因为你的信号弱!尝试在室内使用断开连接的调试器进行测试......
Maybe it works slower because you are debugging, but not because your signal is weak! Try to make tests with disconnected debugger indoors...