【问题标题】:how to get old location from corelocation如何从核心位置获取旧位置
【发布时间】:2013-04-28 09:26:32
【问题描述】:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 

locations 数组最后一个对象持有新位置,如何获取上一个位置?

【问题讨论】:

    标签: ios objective-c core-location


    【解决方案1】:

    您应该创建并使用一个可变的先前位置数组,这些位置是从先前对“locationManager: didUpdateLocations:”的调用中更新的。

    According to the Apple documentation,唯一一次通过委托方法传入的“locations”数组将有多个条目将是“如果更新事件被延迟或者如果多个事件在它们可以被传递之前到达,则数组可能包含其他条目。”

    【讨论】:

    • 特别是,当在 iPhone5 或更新机型上运行并且已开启更新队列时,此调用可能只会在 iOS6 上接收多个位置。
    • @MichealDautermann 非常感谢您的回复,请您再解决一个困惑吗? Apple 在位置感知指南中说:如果位置更新已经交付,您还可以直接从 CLLocationManager 对象获取最新的位置数据,而无需等待新事件的交付。我没有得到这个。请帮忙。
    • 这对我来说听起来像是一个单独的问题......为什么不问一个包含这个细节的新问题呢?
    • @MichaelDautermann 请查看我的新问题stackoverflow.com/questions/16263392/…
    【解决方案2】:

    通过此方法获取更新位置

    func locationManager(_ manager: CLLocationManager,didUpdateLocations locations: [CLLocation]) 
     {
       guard let mostRecentLocation = locations.last else { return }         
       print(mostRecentLocation)
     }
    

    【讨论】:

      猜你喜欢
      • 2011-09-08
      • 2012-01-28
      • 1970-01-01
      • 2016-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-09
      • 1970-01-01
      相关资源
      最近更新 更多