What's an efficient way of calculating the nearest point?

Posted by Griffo on Stack Overflow See other posts from Stack Overflow or by Griffo
Published on 2010-03-11T08:50:22Z Indexed on 2010/03/18 0:41 UTC
Read the original article Hit count: 545

I have objects with location data stored in Core Data, I would like to be able to fetch and display just the nearest point to the current location. I'm aware there are formulas which will calculate the distance from current lat/long to a stored lat/long, but I'm curious about the best way to perform this for a set of 1000+ points stored in Core Data. I know I could just return the points from Core Data to an array and then loop through that looking for the min value for distance between the points but I'd imagine there's a more efficient method, possibly leveraging Core Data in some way.

Any insight would be appreciated.

EDIT: I don't know how I missed this on my initial search but this SO question suggests just iterating through an array of Core Data objects but limiting the array size with a bounding box based on the current location. Is this the best I can do?

© Stack Overflow or respective owner

Related posts about core-data

Related posts about objective-c