こんにちは、現在の位置座標をデータベースに保存するアプリケーションを開発しています。人が2回目に同じ(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
。
助けてください....