Saving mapView.userLocation.location.coordinate.longitude into sqlite database

╄→尐↘猪︶ㄣ 提交于 2020-01-11 11:43:21

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/4635179/saving-mapview-userlocation-location-coordinate-longitude-into-sqlite-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!