-1

我正在尝试获取存储在我的数据库中的某些区域的纬度和经度,并将它们存储在一个数组中。我必须将值存储为浮点类型。我通过以下代码获得其他值:

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];

他们有什么方法可以让我获得纬度和经度的两个浮点值,就像我在我的代码中所做的那样?

请建议....

4

1 回答 1

0

您可以使用:

 float latitude  = (float) sqlite3_column_double(walkstatement, 3);
 float longitude = (float) sqlite3_column_double(walkstatement, 4);

并且可以存储在字典中,例如:

[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];
于 2012-12-18T11:34:54.583 回答