iPhone 3G: How to show locations around a fixed point?
-
08-07-2019 - |
Question
I have my current location fixed via CoreLocation. Now I want to get those locations (from an existing database), which are in the near (about 100 feet) of it.
How do I start?
Update: Here is a implementation of the Haversine formula: http://www.jaimerios.com/?p=39 (very useful)
Solution
CLLocation
provides a method for this:
- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location
You'll need to have the latitude and longitude of each of your records, and then sort by the distance returned by this method.
OTHER TIPS
High school geometry FTW:
dist = sqrt(pow((x2-x1), 2) + pow((y2-y1), 2))
One of the things you can do to make this easier to SQL Query, is to split the map into "tiles", i.e. a 2km x 2km area, so that you can query down to the tile, then loop through the results using this formula.