【发布时间】:2011-03-10 14:14:50
【问题描述】:
在我的 iphone 应用程序中,我有一个带有美国纬度和经度的 sqlite 表(All weather stations of USA)。什么是sqlite查询来检查给定的纬度和经度是否在sqlite的一组纬度/经度中?
我的意思是我将纽约的纬度/经度设置为 (42.75,73.80),(37,-122),但我正在搜索纽约附近的纬度/经度,例如 (42.10,73.20)
如何确定这个 (42.10,73.20) 是否在纽约附近?
- mtoepper 的答案
SQLITE 中的自定义函数(例如 ACOS)
//Include this code in your project
static void ACOSFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
{
assert(argc == 1);
if (sqlite3_value_type(argv[0]) == SQLITE_NULL) {
sqlite3_result_null(context);
return;
}
double input = sqlite3_value_double(argv[0]);
sqlite3_result_double(context, acos(input) );
}
并在创建数据库连接后添加。
sqlite3_create_function(db.sqliteHandle, "ACOS", 1, SQLITE_UTF8, NULL, &ACOSFunc, NULL, NULL);
【问题讨论】:
标签: iphone objective-c sqlite