I have around 2500 records in my SQLite database, each record represents a branch of a well known store in our country, I use distanceFromLocation to compare distance between the current user’s location and a given location like this:
CLLocation* storeLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
double distance = [userLocation distanceFromLocation:storeLocation];
how to use this piece of code (WITH AN EFFICIENT WAY THAT DOES NOT FREEZE UP THE UI) to find the nearest 5 branches among 2500 lat/lon pairs stored in the local SQLite database ?
EDIT :
the code here is an excellent example of how to calculate the distance between two points on the database level, so it’s very efficient, but however, the code is kinda hard to be implemented ‘coz it accesses SQLite and creates queries manually, anybody provides me with a working sample for that code would be highly appreciated.
Check out this (efficient) answer and the comment of Kenny Winker:
https://stackoverflow.com/a/6828849/1611723
It was a similar problem and will help you.