gpt4 book ai didi

android - 在 4.2 之前的 Android 中确定自上次 GPS 位置更新以来耗时的正确方法是什么?

转载 作者:太空狗 更新时间:2023-10-29 14:14:40 25 4
gpt4 key购买 nike

在 <4.2 Android 上确定自上次位置更新以来的时间的正确方法是什么?这是我用过的代码:

long lastUpdateTime = lastLocation.getTime(); 
long currentTime = System.currentTimeMillis();

if (( currentTime - lastUpdateTime > 300000) || currentTime - lastUpdateTime < 0){
LocMan.requestLocationUpdates(LocationManager.GPS_PROVIDER,400,1,listener);
}

可以吗,还是我应该有其他方法?

API 文档说明了这一点:

Note that the UTC time on a device is not monotonic: it can jump forwards or backwards unpredictably. So always use getElapsedRealtimeNanos() when calculating time deltas.

但是,APIv17 之前的版本(其中添加了 getElapsedRealtimeNanos())仍然存在并且需要支持。

感谢您的回答,

最佳答案

我会把它留作评论,但我还没有那个特权。似乎已经有人问过类似的问题。

"How long ago was the last known location recorded?"

关于android - 在 4.2 之前的 Android 中确定自上次 GPS 位置更新以来耗时的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23587692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com