【发布时间】:2013-04-28 09:26:32
【问题描述】:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
locations 数组最后一个对象持有新位置,如何获取上一个位置?
【问题讨论】:
标签: ios objective-c core-location
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
locations 数组最后一个对象持有新位置,如何获取上一个位置?
【问题讨论】:
标签: ios objective-c core-location
您应该创建并使用一个可变的先前位置数组,这些位置是从先前对“locationManager: didUpdateLocations:”的调用中更新的。
According to the Apple documentation,唯一一次通过委托方法传入的“locations”数组将有多个条目将是“如果更新事件被延迟或者如果多个事件在它们可以被传递之前到达,则数组可能包含其他条目。”
【讨论】:
通过此方法获取更新位置
func locationManager(_ manager: CLLocationManager,didUpdateLocations locations: [CLLocation])
{
guard let mostRecentLocation = locations.last else { return }
print(mostRecentLocation)
}
【讨论】: