问题
I am working on a tracer app. The app requires to know the device location with high accuracy, i.e. it uses location services and ignores locations with horizontal accuracy worse than 20 meters. CLLocation
does not declare explicitely if it was determined via GPS or not. However, if the horizontal accuracy is 20 meters or better, it can be supposed that it is a location from GPS.
Additionally, I need to know the timestamp when the location was determined. I know about the property timestamp
in class CLLocation
. However, I would like to get the timestamp from GPS, not the system time.
Is it possible to get the GPS time? I don't care about cases when the GPS signal is not available. I just need to get the GPS time for a GPS location (location with high accuracy) I have just received.
In other questions on stackoverflow, the following code snippet is suggested:
CLLocation* location = [[CLLocation alloc] initWithLatitude:(CLLocationDegrees) 0.0 longitude:(CLLocationDegrees) 0.0];
NSDate* now = location.timestamp;
Is there any guarantee that location.timestamp
is something more GPS-related than [NSDate date]
?
It seems not to be true if the automatic time setting is turned off. If I go to Settings -> General -> Date & Time and turn off "Set Automatically", the property timestamp
contains the manually set system time. So is it more-GPS related at least when automatic time setting is turned on?
回答1:
I think that the timestamp is calculated device-side and is most likely not related to the satellite's timestamp.
CoreLocation is totally opaque in it's work and it sounds very unlikely from Apple to let you access raw data like GPS satellites timestamps...
回答2:
However, I would like to get the timestamp from GPS, not the system time.
You cannot get the timestamp that the GPS chip provides.
If the user artificially sets a wrong time, ios uses this offset in its locations, too.
I just need to get the GPS time for a GPS location (location with high accuracy) I have just received.
If the device is set to auto setting the system time, the gps location time should be acurate.
So is it more-GPS related at least when automatic time setting is turned on?
Yes
Is there any guarantee that location.timestamp is something more GPS-related than [NSDate date]?
Its always more related, [NSDate date] is the current system time, while location.time is the time related to the location recording time. This can be offset by e.g 0.6s, or even much more for the first fix after start.
To check whether the location is current or not, Apple recomends to calcuilate the difference between system time and location time.
来源:https://stackoverflow.com/questions/31920829/getting-time-from-gps-on-ios