I have a Core Data database with latitude and longitude properties. Is there a way to use Core Location’s getDistanceFrom: method to find the five nearest locations to a CLLocation obtained from the GPS? Do I have to load all the objects using Core Data and parse through them, using getDistanceFrom: on each one or is there an easier way?
I have a Core Data database with latitude and longitude properties. Is there a
Share
You will have to iterate through them one by one; as far as I know there is no other way to do it.
However, you can make this more efficient by using a bounding box when you get the items from core data – this will reduce the number of objects that will be returned.
i.e. Something like
Though, depending on how much data you have and how closely it’s spaced, you will want to use a different number than 1!
PS Also, I haven’t taken into account the fact that longitude wraps!