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

发布于 2024-10-10 16:43:30 字数 319 浏览 0 评论 0原文

我想将从 mapView.userLocation.location.coordinate.longitude 返回的值插入到我的 sqlite3 数据库中。我不确定它的类型。我不能这样做:

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

它给出了“无法转换为指针类型”错误,因为我猜经度不是浮点数。

数据库表中字段类型为FLOAT。如何将经度值转换为浮点数?

多谢。

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.

The type of field is FLOAT in the database table. How can I convert the value of longitude to float from whatever it is?

Thanks a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

口干舌燥 2024-10-17 16:43:30

MKUserLocation 的文档显示位置属性的类型为 CLLocation。 CLLocation 的文档显示坐标属性的类型为 CLLocationCooperative2D。

核心位置数据类型参考表明 CLLocationCooperative2D 是一个包含纬度和经度的结构体,每个纬度和经度的类型均为 CLLocationDegrees。

在同一页面上,CLLocationDegrees 显示为 double 的另一个名称。所以纬度和经度都是 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);

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.

The Core Location Data Types Reference shows that CLLocationCoordinate2D is a struct containing latitude and longitude each of which is of type CLLocationDegrees.

On the same page, CLLocationDegrees is shown to be just another name for double. So latitude and longitude are of type 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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文