5

I'm tracking GPS locations with LocationManager.requestLocationUpdates() using LocationManager.GPS_PROVIDER and registering a LocationListener.

My Problem:

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>

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.

My question:

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)?

Remarks:

Community
  • 1
  • 1
hgoebl
  • 12,637
  • 9
  • 49
  • 72
  • Did you get to a conclusion ? – Kristian Benoit Apr 02 '15 at 17:14
  • For me it looks like `Location.getTime()` is a very accurate time, but without milliseconds. So someone could set the time of the device by using this value. `System.currentTimeMillis()` seams to be more accurate, but this is not true. If you set the clock of the device wrongly, you'll get wrong values from this call. In my case, I'm not interested in exact time in space, but in delta time between calls, so I use `System.currentTimeMillis()`. – hgoebl Apr 04 '15 at 17:15

1 Answers1

0

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.

  • Thanks. I use `System.currentTimeMillis` for all other sensors (e.g. barometric pressure) and `Location.getTime()` uses the same semantic (milliseconds since 1970 UTC). But the **big question** is: is GPS data outdated at the time it arrives in my listener? How much out-dated? A few millis or possibly a few seconds? – hgoebl May 30 '14 at 16:26
  • I believe it is outdated by a few mills, have you tried `System.nanoTime()`? I think it's more precise compared to `System.currentTimeMillis`, but I haven't tried it out for android – user3203324 May 30 '14 at 16:31