I have a list of core data objects each has a longitude and latitude properties.
I have the user location from core location.
I wish to retrieve the nearest object to the user location?
How can I do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m not going to give you an answer with code as you are only asking a general question.
But, there is a useful function in
CLLocationcalleddistanceFromLocation:which has the signature:The way to do this would be to store (or create) create CLLocation objects from the locations in your Core Data store, and using the users current location you can iterate through the list of locations using this function to get the distances and then return the location with the smallest return value as the nearest location.