问题
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