2 daffodilgirl DaffodilGirl 于 2012.12.29 11:33 提问

获取数据库经纬度的浮点数值

我想要获取数据空中指定范围的经纬值,然后以浮点类型存储在数组中。我用下面的代码获取:

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

有没有什么方法可以获取经纬度值的浮点类型值?谢谢

1个回答

yue1liang1chuan
yue1liang1chuan   2012.12.29 13:34
已采纳

可以用:

 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];
DaffodilGirl
DaffodilGirl 谢谢
接近 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!