简体   繁体   中英

how to get old location from corelocation

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

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

You should create and use a mutable array of previous locations that were updated from previous calls to " locationManager: didUpdateLocations: ".

According to the Apple documentation , the only time that " locations " array passed in via the delegate method will have more than one entry will be "If update events were deferred or if multiple events arrived before they could be delivered, the array may contain additional entries."

Get updated location in this method

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM