Hey,
I am sorting stores to get the closest stores. Furthermore I want to know how far away this shop is. The SQL query would look like this:
select *,
6371 * 2 * ATAN2(SQRT(POWER(SIN((RADIANS(?) - RADIANS(latitude))/2),2) + COS(RADIANS(latitude)) * COS(RADIANS(?)) * POWER(SIN((RADIANS(?) - RADIANS(longitude))/2),2)), SQRT(1-POWER(SIN((RADIANS(?) - RADIANS(latitude))/2),2) + COS(RADIANS(latitude)) * COS(RADIANS(?)) * POWER(SIN((RADIANS(?) - RADIANS(longitude))/2),2))) AS DISTANCE
FROM stores
ORDER BY DISTANCE
these question marks would be replaced by the longitude and latitude of the users position. (latitude, latitude, longitude, latitude, latitude, longitude)
How can I achieve this with iPhone SDK using Core Data?