问题描述
我想将从mapView.userLocation.location.coordinate.longitude返回的值插入到我的sqlite3数据库中.我不确定它的类型.我不能这样:
I want to insert the value returning from mapView.userLocation.location.coordinate.longitude into my sqlite3 database. I am not sure of its type. I cannot do it this way:
sqlite3_bind_text(stmt, 1, [mapView.userLocation.location.coordinate.longitude floatValue], -1, nil);
我认为这会导致无法转换为指针类型" 错误,因为经度不是浮动的.
It gives "Cannot convert to a pointer type" error because longitude is not float, I guess.
数据库表中字段的类型为FLOAT.如何将经度值转换为浮点值?
The type of field is FLOAT in the database table. How can I convert the value of longitude to float from whatever it is?
非常感谢.
推荐答案
MKUserLocation的文档显示location属性的类型为CLLocation. CLLocation的文档显示,ordinate属性的类型为CLLocationCoordinate2D.
The documentation for MKUserLocation shows that the location property is of type CLLocation. The docs for CLLocation show that the coordinate property is of type CLLocationCoordinate2D.
核心位置数据类型参考显示CLLocationCoordinate2D是一个包含纬度和经度的结构,每个结构的类型均为CLLocationDegrees.
The Core Location Data Types Reference shows that CLLocationCoordinate2D is a struct containing latitude and longitude each of which is of type CLLocationDegrees.
在同一页面上,CLLocationDegrees被显示为double
的另一个名称.因此,纬度和经度是double类型的.
On the same page, CLLocationDegrees is shown to be just another name for double
. So latitude and longitude are of type double.
因此,不要使用sqlite3_bind_text
,而要使用sqlite3_bind_double
:
So instead of using sqlite3_bind_text
, use sqlite3_bind_double
:
sqlite3_bind_double(stmt, 1, mapView.userLocation.location.coordinate.longitude);
并加载该值,您将使用类似以下内容的
and to load the value, you would use something like:
double longitude = sqlite3_column_double(stmt, column_index_here);
这篇关于将mapView.userLocation.location.coordinate.longitude保存到sqlite数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!