使用 MKMapView、核心位置和核心数据

Using MKMapView, Core Location, and Core Data

所以我正在学习核心数据和核心位置,我有点卡在如何用核心数据保存核心位置数据。我想做的是:用户输入一个地址,它显示在 MKMapView 中(我已经把这部分记下来了),然后用户按下一个按钮 'save' 并保存位置,关闭屏幕并返回到上一个屏幕(这是一个 UITableView)并将该位置添加到 table.

我的保存方法应该是什么样子?

提前致谢!

从您的地图获取位置,经纬度

  1. 用于更轻松地处理核心数据MagicalRecord
  2. 在您的数据库架构中创建 MapLocation "Entity" .创建 属性 "lat",键入 float .创建 属性 "long",键入 float
  3. 为您的 "Entity"
  4. 创建文件 nsManagedObject
  5. 您要保存位置的位置:

    位置 *locationInsert = [位置 mr_createEntity]; locationInsert.lat = 我的纬度; locationInsert.long = myLong;

    //保存

    NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread]; [localContext MR_saveToPersistentStoreAndWait];