Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPhone - SQLite distance by Latitude and Longitude

I have a embedded database in my app that has all Latitude and Longitude of some interested points and I need to know my distance from these points(get my position using GPS). My problem is: I've just figured out that SQLite can't calculate distance using the query that I have because it doesn't calculate trigonometry functions(SIN, COS...). I was trying to avoid calculating these distances programatically using this query:

NSLog(@"SELECT ((ACOS(SIN(%@ * PI() / 180) * SIN(lat * PI() / 180) + COS(%@ * PI() / 180) * COS(lat * PI() / 180) * COS((%@ – lon) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS `distance` FROM `members` HAVING `distance`<=’1000′ ORDER BY `distance`", Latitude,Latitude, Longitude);

Does anybody has a solution?

Regards!

like image 806
Claudio Avatar asked Jul 26 '11 10:07

Claudio


1 Answers

Do it in Objective C.

this guy had the same problem: http://www.thismuchiknow.co.uk/?p=71

like image 156
Jeroen Coupé Avatar answered Nov 19 '22 20:11

Jeroen Coupé