我想要獲取數據空中指定范圍的經緯值,然後以浮點類型存儲在數組中。我用下面的代碼獲取:
NSString *walkQuery = [[NSString alloc] initWithFormat:@"SELECT Wid,WName,SName,Latitude,Longitude from Walks,SubRegions WHERE Walks.Sid=SubRegions.Sid AND Rid = %d",[regionId integerValue] ];
sqlite3_stmt *walkstatement = nil;
if (sqlite3_prepare_v2(walkNameDB,[walkQuery UTF8String], -1, &walkstatement, nil) == SQLITE_OK)
{
while( sqlite3_step(walkstatement) == SQLITE_ROW )
{
NSNumber *WId;
int temp1 = (int)sqlite3_column_int(walkstatement, 0);
WId = [[NSNumber alloc] initWithInt:temp1];
char *WNameCharacter;
WNameCharacter = (char *) sqlite3_column_text(walkstatement, 1);
NSString *WNameString = [[NSString alloc] initWithUTF8String:WNameCharacter];
char *SNameCharacter;
SNameCharacter = (char *) sqlite3_column_text(walkstatement, 2);
NSString *SNameString = [[NSString alloc] initWithUTF8String:SNameCharacter];
NSMutableDictionary *tempWalk = [[NSMutableDictionary alloc] init];
[tempWalk setObject:WId forKey:@"WalkId"];
[tempWalk setObject:WNameString forKey:@"WalkName"];
[tempWalk setObject:SNameString forKey:@"SubRegionName"];
[regionWalkArray addObject:tempWalk];
有沒有什麼方法可以獲取經緯度值的浮點類型值?謝謝
可以用:
float latitude = (float) sqlite3_column_double(walkstatement, 3);
float longitude = (float) sqlite3_column_double(walkstatement, 4);
然後在dictionary中存儲:
[tempWalk setObject:[NSNumber numberWithFloat:latitude] forKey:@"latitude"];
[tempWalk setObject:[NSNumber numberWithFloat:longitude] forKey:@"longitude"];
附贈檢索:
float latitude = [[tempWalk objectForKey:@"latitude"] floatValue];
float longitude = [[tempWalk objectForKey:@"longitude"] floatValue];