Android GPS time is 15 seconds faster

I am synchronizing the time of my applications with the method android.location.Location getTime()inside the method call onLocationChanged. The problem is that on some devices the result is right, on some - 15 seconds faster. As I know, this is due to GPS time and UTC difference .

How to check that the device knows about this difference? I need my application to show the same time on all devices.

I can not use network synchronization as a solution.

+4
source share
2 answers

According to the docs :

public long getTime ()

Return the UTC time of this fix, in milliseconds since January 1,
1970.

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.

On the other hand, getTime() is useful for presenting a human readable
time to the user, or for carefully comparing location fixes across
reboot or across devices.

All locations generated by the LocationManager are guaranteed to have
a valid UTC time, however remember that the system time may have
changed since the location was generated. 

Returns

time of fix, in milliseconds since January 1, 1970.

Have you tried getElapsedRealtimeNanos ()?

Date, :

Date date = new Date(System.currentTimeMillis() 
                   - SystemClock.elapsedRealtime() 
                   + location.getElapsedRealtimeNanos());
+4

.

GPS UTC

-, , GPS UTC. GPS , UTC, . . , GPS- GPS , GPS-.

Android API , NMEA ( , Android ), , .

PDF, , GPS, . GPS/UTC.

, , GPS- AGPS ( GPS), , , GPS, , , , .

, WiFi ( , , ...), 12,5 , GPS UTC GPS.

GPS-. , , .

, . GPS AFAIK, - OS/GPS, - leiu, - , . , , , Android ​​ ( ...).

, NTP , . Linux NTP, , - NTP. ( AFAIK Android) , , . , , 15 , - .

+3

Source: https://habr.com/ru/post/1584446/


All Articles