您好正在开发一个将当前位置坐标存储到数据库中的应用程序,当一个人第二次到达相同(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);
}
有了这个距离函数没有调用,并且prepareV2语句也没有执行,如果我将“ ORDERBY distance Query
”替换为SELECT * from Table PrepareV2
正在执行。
任何帮助请......