2011-01-08 173 views
1

我想要將從mapView.userLocation.location.coordinate.longitude返回的值插入到我的sqlite3數據庫中。我不確定它的類型。我不能做這種方式:將mapView.userLocation.location.coordinate.longitude保存到sqlite數據庫

sqlite3_bind_text(stmt, 1, [mapView.userLocation.location.coordinate.longitude floatValue], -1, nil); 

它給「無法轉換爲指針類型」錯誤,因爲經度不浮動,我猜。

字段的類型是數據庫表中的FLOAT。我怎樣才能將經度值轉換爲浮動值?

非常感謝。

+0

使用[FMDB](http://github.com/ccgus/FMDB)。 – 2011-01-08 19:11:55

+2

爲了將來的參考@ozancali,你可以簡單地按住選項鍵並雙擊一個屬性/變量,它會告訴你它是什麼類型,並直接提供一個快捷方式到文檔和示例代碼。如果您按住命令鍵並雙擊,它會直接將您帶到propery /變量的標題定義。 – 2011-01-08 19:51:50

回答

4

MKUserLocation的文檔顯示location屬性的類型爲CLLocation。 CLLocation的文檔顯示座標屬性的類型爲CLLocationCoordinate2D。

Core Location Data Types Reference顯示CLLocationCoordinate2D是一個包含經度和緯度的結構,每個結構都是CLLocationDegrees類型。

在同一頁上,CLLocationDegrees顯示爲double的另一個名稱。所以經緯度是雙重的。的

因此而不是使用sqlite3_bind_text,使用sqlite3_bind_double

sqlite3_bind_double(stmt, 1, mapView.userLocation.location.coordinate.longitude); 

並加載值,你會使用類似:

double longitude = sqlite3_column_double(stmt, column_index_here);