您正在开发一个应用程序,它将当前位置坐标存储到数据库中,当一个人第二次到达同一位置(在100米内)时,我需要显示一个警报。为此我使用了sqlite的距离在打开sqlite数据库后提供堆栈溢出。然后我正在使用
SELECT * from table ORDER BY distance
我用过这段代码......
if (sqlite3_open([dbPath UTF8String], &dataBase) == SQLITE_OK) {
sqlite3_create_function(dataBase, "distance", 4, SQLITE_UTF8, NULL, &distanceFunc, NULL, NULL);
NSString *sqlQuery=[NSString stringWithFormat:@"SELECT * FROM %@ ORDER BY distance(uacl_latitude,uacl_lognitude,%f,%f)",NSLocalizedString(@"TABLE_USER_LOCATION", nil),[self.currentLatitude doubleValue],[self.currentLongitude doubleValue]];
NSLog(@"%@",sqlQuery);
sqlite3_stmt *selectstmt = NULL;
if(sqlite3_prepare_v2(dataBase,[sqlQuery cStringUsingEncoding:NSASCIIStringEncoding],-1,&selectstmt,NULL)==SQLITE_OK) {
while(sqlite3_step(selectstmt) == SQLITE_ROW) {
self.latitude =sqlite3_column_double(selectstmt, 4);
self.longitude = sqlite3_column_double(selectstmt, 5); NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%f",self.latitude],@"LATI",[NSString stringWithFormat:@"%f",self.longitude],@"LONGI",nil];
[array addObject:dict];
}
}
} else {
//Even though the open call failed, close the database connection to release all the memory.
sqlite3_close(dataBase);
}
这样,距离函数没有调用,如果我替换正在执行ORDERBY distance Query
的“SELECT * from Table PrepareV2
”,则prepareV2语句也没有执行。
请帮助....