使用模拟器进行定位修复的时间已关闭

发布于 2024-12-18 10:30:13 字数 743 浏览 1 评论 0原文

我正在编写一些 Android 代码来测试地理位置库,但我遇到了 Android 模拟器的问题。我正在创建一个 LocationListener,当调用 LocationListener::onLocationChanged 时,我检查传入的 Location 对象的时间,以将其与当前时间进行比较。我使用 DDMS 模拟器控制窗口来更改位置以触发对 onLocationChanged 的​​调用。这是我在 onLocationChanged 方法中使用的代码,用于将传入的位置时间与当前时间进行比较(“位置”是传递到 onLocationChanged 的​​位置):

float accuracy = location.getAccuracy();
long curTime = System.currentTimeMillis();
float lateness = (curTime - location.getTime()) / 1000;

我遇到的问题是我从位置获取的时间使用 getTime 总是远离当前时间 (curTime),即使我使用 DDMS 设置位置和在调试器中查看它的时间之间的时间只有几秒钟。通常差异是几个小时,有时来自位置的时间比当前时间早几个小时(因此位置修复的时间发生在未来几个小时?!?)。另外,时间差也不一致。调用 Location::getTime 和 System.currentTimeMillies 的文档均表示返回的时间以 UTC 1970 年 1 月 1 日以来的毫秒为单位,因此不应该是使用不同时区的问题。这是模拟器的已知错误还是我做错了什么?谢谢!

I'm writing some android code to test out the geolocation libraries and I'm running into a problem with the android emulator. I am creating a LocationListener and when LocationListener::onLocationChanged is called I check the time of the passed in Location object to compare it to the current time. I use the DDMS emulator control window to change the location to trigger the call to onLocationChanged. Here is the code that I use in the onLocationChanged method to compare the passed in location time to the current time ("location" is the location that is passed into onLocationChanged):

float accuracy = location.getAccuracy();
long curTime = System.currentTimeMillis();
float lateness = (curTime - location.getTime()) / 1000;

The problem I'm having is that the time I get from location using getTime is always way off of the current time (curTime) even though the time between when I set the location using DDMS and the time I look at it in the debugger is a matter of seconds. Usually the difference is several hours, and sometimes the time from location is several hours ahead of the current time (so the time of the location fix occurs several hours in the future?!?). Additionally, the time diffference is not consistent. The documentation for the call to Location::getTime and System.currentTimeMillies both say that the returned time is given in milliseconds since Jan 1 1970 UTC, so it shouldn't be an issue of using different time zones. Is this a known bug with the emulator or is there something I'm doing wrong? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

GPS 时间实际上与设备上的时间不同。因此,它们可能存在很大差异。 Wiki 有一个很好的解释这里

GPS time is actually different from time on the device. So, they can differ by a huge amount. Wiki has a nice explanation here

落花随流水 2024-12-25 10:30:13

有关此问题的更多信息,请访问Android 模拟器的 GPS 位置给出错误的时间 以及错误报告链接。另外 Android 无法确定最近的最新版本GPS 修复 以及系统时间和 GPS 时间不匹配的原因可能值得一读。

More information about this can be found at Android emulator's GPS location gives wrong time as well as the bug report link. Additionally Android problem finding out how recent latest GPS fix is may be worth reading as well as to why system time and GPS time won't match.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文