首页 文章

在iOS上从GPS获取时间

提问于
浏览
4

我正在研究一个跟踪器应用程序 . 该应用程序需要高精度地知道设备位置,即它使用位置服务并忽略水平精度低于20米的位置 . CLLocation 如果是通过GPS确定,则不会明确声明 . 但是,如果水平精度为20米或更高,则可以认为它是来自GPS的位置 .

另外,我需要知道确定位置时的时间戳 . 我知道类 CLLocation 中的属性 timestamp . 但是,我想从GPS获取时间戳,而不是系统时间 .

是否有可能获得GPS时间?我不关心GPS信号不可用的情况 . 我只需要获得我刚刚收到的GPS位置(高精度位置)的GPS时间 .

在stackoverflow的其他问题中,建议使用以下代码段:

CLLocation* location = [[CLLocation alloc] initWithLatitude:(CLLocationDegrees) 0.0 longitude:(CLLocationDegrees) 0.0];
NSDate* now = location.timestamp;

是否有保证 location.timestamp 与GPS相关的东西比 [NSDate date]

如果关闭自动时间设置似乎不是这样 . 如果我转到设置 - >常规 - >日期和时间并关闭"Set Automatically",属性 timestamp 包含手动设置的系统时间 . 那么至少在开启自动时间设置时它是否与GPS相关?

2 回答

  • 2

    我认为时间戳是在设备端计算的,很可能与卫星的时间戳无关 .
    CoreLocation在它的工作中是完全不透明的,并且听起来Apple不太可能让你访问GPS卫星时间戳这样的原始数据......

  • 1
    However, I would like to get the timestamp from GPS, not the system time.
    

    您无法获得GPS芯片提供的时间戳 .

    如果用户人为地设置了错误的时间,ios也会在其位置使用此偏移量 .

    I just need to get the GPS time for a GPS location (location with high accuracy) I have just received.
    

    如果设备设置为自动设置系统时间,则应该确定gps位置时间 .

    So is it more-GPS related at least when automatic time setting is turned on?
    

    Is there any guarantee that location.timestamp is something more GPS-related than [NSDate date]?
    

    它总是更相关,[NSDate date]是当前系统时间,而location.time是与位置记录时间相关的时间 . 对于启动后的第一次修复,这可以抵消0.6s,甚至更多 .

    为了检查位置是否是最新的,Apple建议计算系统时间和位置时间之间的差异 .

相关问题