在 iPhone 项目中实现 sqlite 的 Haversine 函数
因此,经过一个小时的研究,我发现大多数人似乎都同意 http 上的功能://www.thismuchiknow.co.uk/?p=71 是在 iPhone 项目中实现半正矢函数的方法,当您拥有充满纬度和经度的数据库时,可以按距离对结果进行排序。不过,对于如何将其实际包含在您的项目中似乎没有什么帮助,而且我自己也没有运气。
无论我将该函数添加到 ViewController.m 文件中的哪个位置,我都会收到错误 expected ')' before '*' token
。有些人提到您需要将 static void distanceFunc(sqlite3_context *context, int argc, sqlite3_value **argv); 放入 .h 文件中,但我也遇到了同样的错误。
谁能提供一个在 iPhone 项目中包含此功能的简单示例吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以使用这个,
或者将你的viewController文件的.m扩展名更改为.mm。(你也可以尝试这个)
更新
尝试更新一个。
谢谢,
your can use this,
or change .m extention of your viewController file to .mm.(You can try this one also)
updated
try updated one.
Thanks,
将代码插入到
.m
文件中任意位置提供的链接中应该没有问题。如果您在函数定义行上收到错误,则编译器很可能不知道sqlite3_context
是什么。这意味着您尚未在 .m 文件中包含sqlite3.h
标头。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 ansqlite3_context
is. This means you haven't include thesqlite3.h
header in your .m file.好的,所以我的问题是不使用
#import
和不将libsqlite3.0.dylib
框架添加到我的项目中。至于将 http://www.thismuchiknow.co.uk/ 中的函数放置在哪里? p=71,我将其放在控制器的.m
文件中的#import
标记和@synthesize
之间,显示如下博客文章中确实如此。Ok, so my problem was a combination of not using
#import <sqlite3.h>
and not adding thelibsqlite3.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.