I'm using Xcode 7 with iOS9. I want to sort a list ascending, based on distance from users current location to all other locations in the list.
I don't want to calculate the distance to a location by coordinates, but by address because the distance depends on the choosen method (drive / walk). All I want to do is save the address in each location object to calculate the distance to that object later on.
When initializing the list with objects I'm doing this request in each object's initializer:
let location = CLLocation(latitude: latitude, longitude: longitude) //changed!!!
CLGeocoder().reverseGeocodeLocation(location, completionHandler: {(placemarks, error) -> Void in
//the code to obtain an address and save it in a location object is here and works
}
The problem I have now is that I have to send 172 such reverseGeocodeLocation requests as my list contains 172 objects and I need to calculate the distance from my users location to each object's location.
Sending so many requests so fast results in this error: The operation couldn’t be completed. (kCLErrorDomain error 2.)
Is there a way to solve this? If things aren't clear tell me please so I can clarify