0
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 

位置数组最后一个对象保存新位置,如何获取上一个位置?

4

2 回答 2

3

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

根据 Apple 文档locations,通过委托方法传入的“”数组将包含多个条目的唯一时间是“如果更新事件被推迟,或者如果多个事件在它们可以被传递之前到达,则数组可能包含额外的条目。”

于 2013-04-28T09:31:17.467 回答
0

在此方法中获取更新的位置

func locationManager(_ manager: CLLocationManager,didUpdateLocations locations: [CLLocation]) 
 {
   guard let mostRecentLocation = locations.last else { return }         
   print(mostRecentLocation)
 }
于 2021-02-04T18:08:17.763 回答