简体   繁体   English

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

[英]Using MKMapView, Core Location, and Core Data

So I'm in the process of learning core data and core location and I'm a little stuck on how to save core location data with core data. 因此,我正在学习核心数据和核心位置,并且对如何使用核心数据保存核心位置数据有些困惑。 What I'm trying to do is this: the user types in an address and it is displayed in MKMapView (I've got this part down), then the user pushes a button 'save' and it saves the location, dismisses the screen and goes back to the previous screen (which is a UITableView) and adds that location to the table. 我想做的是:用户输入一个地址,并显示在MKMapView中(我把这个部分放下了),然后用户按下按钮“保存”,它保存了位置,关闭了屏幕然后返回上一屏幕(即UITableView),并将该位置添加到表中。

How should my save method look? 我的保存方法应如何显示?

Thanks in advance! 提前致谢!

get the location from your map, lat long 从您的地图上获取位置

  1. use for dealing with core data easier MagicalRecord 用于处理核心数据更容易MagicalRecord
  2. create MapLocation "Entity" in your db schema . 在数据库架构中创建MapLocation“ Entity”。 create property "lat", type float . 创建属性“ lat”,输入float。 create property "long", type float 创建属性“ long”,输入float
  3. create file nsManagedObject for your "Entity" 为您的“实体”创建文件nsManagedObject
  4. where you want to save your location: 您要保存位置的位置:

    Location *locationInsert = [Location mr_createEntity]; 位置* locationInsert = [位置mr_createEntity]; locationInsert.lat = myLat; locationInsert.lat = myLat; locationInsert.long = myLong; locationInsert.long = myLong;

    //Save //救

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM