位置管理器:
- (void)setupLocationRecord:(CLLocation *)location {
LocationRecord *locationRecord = [LocationRecord createEntity];
locationRecord.latitude = [NSNumber numberWithDouble:location.coordinate.latitude];
locationRecord.longitude = [NSNumber numberWithDouble:location.coordinate.longitude];
locationRecord.createdAt = [NSDate date];
locationRecord.updatedAt = [NSDate date];
[[NSManagedObjectContext defaultContext] saveNestedContexts];
//[self performSelectorInBackground:@selector(addLocation:) withObject:locationRecord];
[locationRecord debug];
[self addLocation:locationRecord];
}
地图视图控制器:
- (void)setupMap {
NSArray *array = [LocationRecord findAllSortedBy:@"idLocation" ascending:YES];
NSLog(@"%s %@", __PRETTY_FUNCTION__, array);
self.mapView.locationsRecordList = [[NSMutableArray alloc] initWithArray:array];
}