简体   繁体   中英

Implementing a Haversine function for sqlite into an iPhone project

So after an hour of research, I've found that most people seem to agree that the function at http://www.thismuchiknow.co.uk/?p=71 is the way to go for implementing a Haversine function into an iPhone project for ordering results by distance when you have a database full of latitudes and longitudes. There seems to be little help on how to actually include it in your project though, and I'm having no luck on my own.

No matter where I add the function into my ViewController.m file, I get the error expected ')' before '*' token . Some people have mentioned you need to put static void distanceFunc(sqlite3_context *context, int argc, sqlite3_value **argv); into your .h file, but I get the same error there too.

Can anyone provide a brief example of including this function in an iPhone project?

your can use this,

+(void)distanceFunc(sqlite3_context *context, int argc, sqlite3_value **argv);

or change .m extention of your viewController file to .mm.(You can try this one also)

updated

+(void)distanceFunc:(sqlite3_context *)context arg1:(int)argc arg2:(sqlite3_value **)argv;

try updated one.

Thanks,

There should be no problem with inserting the code in the link you gave anywhere in a .m file. If you are getting the error on the function definition line, it is likely that the compiler doesn't know what an sqlite3_context is. This means you haven't include the sqlite3.h header in your .m file.

Ok, so my problem was a combination of not using #import <sqlite3.h> and not adding the libsqlite3.0.dylib framework to my project. As far as where to place the function from http://www.thismuchiknow.co.uk/?p=71 , I put it between my #import tags and @synthesize in my controller's .m file, appearing just as it does in the blog post.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM