views:

431

answers:

2

Hi,

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)

A: 

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.

Paul Betts
But I can't apply this formula each of my locations (it's a database with round about 3500 locations). So I thought there would be a resource friendly method, which is included in CL.
Stefan
This isn't a good way as the earth is spherical and you are preforming a direct line measurement for point A to point b.
David Wong
He wants to know things that are within 100 feet of the current location, I don't think you have to worry about spherical distortion here :)
Paul Betts
+7  A: 

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.

pgb