問題描述
我正在通過 LocationManager.requestLocationUpdates()
使用 LocationManager.GPS_PROVIDER
跟蹤 GPS 位置并注冊 LocationListener
.
I'm tracking GPS locations with LocationManager.requestLocationUpdates()
using LocationManager.GPS_PROVIDER
and registering a LocationListener
.
我的問題:
所有經(jīng)過測試的設(shè)備(Sony neo、Sony active、Moto G)都會生成 Location
對象,這些對象在其 getTime()
中沒有幾分之一秒:
All tested devices (Sony neo, Sony active, Moto G) produce Location
objects which do not have fractions of a second in their getTime()
:
<trkpt ...><time>2014-05-24T10:24:59.000Z</time></trkpt>
<trkpt ...><time>2014-05-24T10:25:00.000Z</time></trkpt>
<trkpt ...><time>2014-05-24T10:25:01.000Z</time></trkpt>
<trkpt ...><time>2014-05-24T10:25:02.000Z</time></trkpt>
<trkpt ...><time>2014-05-24T10:25:03.000Z</time></trkpt>
當我計算速度、傾斜和與氣壓高度合并時,1 秒(1000 毫秒)的分辨率太不精確了.而且我不相信所有的修復(fù)都是完全在.000
.
As I'm calculating speed, incline and merge with barometic altitude, 1s (1000ms) resolution is way too imprecise. And I do not believe, that the fixes are all exactly at .000
.
我的問題:
最好將 System.currentTimeMillis()
作為我的跟蹤點的時間戳,或者 GPS 定位通常遠??遠落后于實時",并且計算出的位置實際上是來自過去(落后幾秒)?
Is is better to take System.currentTimeMillis()
as the timestamp for my track-points, or is the GPS fix generally far behind "real time" and the calculated positions are actually those from the past (several seconds behind)?
備注:
- 我知道在使用 GPS 數(shù)據(jù)時速度計算并不精確且相當復(fù)雜
- 這不是 Matching Location.getTime() 毫秒到 NMEA 語句 的副本
推薦答案
根據(jù)我的經(jīng)驗,System.currentTimeMillis()
是一種更好的獲取時間戳的方法,這就是我正在做的事情我的應(yīng)用程序.但是,請注意,如 android 開發(fā)者網(wǎng)站所述,System.currentTimeMillis() 返回自 1970 年 1 月 1 日 00:00:00.0 UTC 以來的當前時間(以毫秒為單位)
所以它真的取決于什么你想用它.正如我所提到的,我發(fā)現(xiàn)它比其他形式的時間戳更可靠,它可能最適合您的情況.
In my experience, System.currentTimeMillis()
is a much better way to take timestamps, and it is what I am doing in my app. However, please be advised that, as stated on the android developer site, System.currentTimeMillis() Returns the current time in milliseconds since January 1, 1970 00:00:00.0 UTC
so it really depends on what you want to use it for. As I mentioned though, I found it to be more reliable than other forms of timestamps and it is probably best suited for your case.
這篇關(guān)于Location.getTime() 總是返回沒有毫秒的時間戳的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!