将mapView.userLocation.location.coordinate.longitude保存到sqlite数据库

将mapView.userLocation.location.coordinate.longitude保存到sqlite数据库

问题描述:

我想要将从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

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