程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> iphone-獲取數據庫經緯度的浮點數值

iphone-獲取數據庫經緯度的浮點數值

編輯:編程綜合問答
獲取數據庫經緯度的浮點數值

我想要獲取數據空中指定范圍的經緯值,然後以浮點類型存儲在數組中。我用下面的代碼獲取:

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];
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved