2

So, as of iOS 6, -locationManager:didUpdateToLocation:fromLocation: is deprecated.

Apple suggests, instead, using -locationManager:didUpdateLocations:, which provides anywhere from one to a series of recent location changes. However, in the incredibly likely chance it provides a locations array of length 1, there appears to be no way to access the fromLocation:(CLLocation *)oldLocation parameter of old.

Is there a way to get at this information without using deprecated methods?

Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
Patrick Perini
  • 22,555
  • 12
  • 59
  • 88

2 Answers2

1

You just need to set a property to the value that locationManager:didUpdateLocations: returns, which you can use as the fromLocation, and then call the method again, and use what it returns as the toLocation.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • I assume that when you say "call the method again" you mean wait until the `CLLocationManager` calls it on your behalf. – Rob Nov 15 '12 at 07:10
  • 1
    Yes, that's what I meant, although you can control when it gets called somewhat by setting the distance filter. – rdelmar Nov 15 '12 at 07:27
  • Very good. I apologize, therefore, for my rather duplicative answer and have adjusted to give you due credit! – Rob Nov 15 '12 at 07:31
0

As rdelmar said, if you need the previous location, I would just store the last location received from locationManager:didUpdateLocations: in an ivar or property, and if locationManager:didUpdateLocations: returns an array with only one value, grab the value you previously saved in your ivar/property and use that for your "old" location.

Rob
  • 415,655
  • 72
  • 787
  • 1,044