I sort the stores to get the closest stores. In addition, I want to know how far this store is. The SQL query will 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 will be replaced by the longitude and breadth of users. (latitude, latitude, longitude, latitude, latitude, longitude)
How can I achieve this using the iPhone SDK using Core Data?
source share