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

后端 未结 1 1254
没有蜡笔的小新
没有蜡笔的小新 2021-01-25 03:13

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:

<
相关标签:
1条回答
  • 2021-01-25 03:46

    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);
    
    0 讨论(0)
提交回复
热议问题