我正在制作的应用程序Polyline根据用户坐标绘制CLLocationManager(这些都保存在一起NSMutableArray)
当应用关闭时,当前折线消失.如何在应用程序启动时存储要在CoreData中检索的点数组?用户在启动应用程序后所采取的所有过去"路线"应该被恢复并覆盖在地图上(这可能相当多,因此CoreData似乎是我收集的最佳选择).
这是我用来从加载的坐标创建MKPolyline的代码
-(IBAction)didClickLoadCoordinates:(id)sender {
// get a reference to the appDelegate so you can access the global managedObjectContext
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Route"];
NSError *error;
id results = [appDelegate.managedObjectContext executeFetchRequest:request error:&error];
if ([results count]) {
polyLine = (Route *)(results[0]);
NSArray *coordinates = polyLine.coordinates;
int ct = 0;
for (CLLocation *loc in coordinates) {
NSLog(@"location %d: %@", ct++, loc);
}
// this copies the array to your mutableArray …Run Code Online (Sandbox Code Playgroud)