S.J
S.J

Reputation: 3071

how to get old location from corelocation

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

locations array last object holds new location, How to get the previous location?

Upvotes: 0

Views: 628

Answers (2)

Asfar Hussain Siddiqui
Asfar Hussain Siddiqui

Reputation: 562

Get updated location in this method

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

Upvotes: 0

Michael Dautermann
Michael Dautermann

Reputation: 89569

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."

Upvotes: 3

Related Questions