I'm attempting to build an app which will track a route, then store the route in parse.com so I can overlay the route taken by a user using MKpolyline.
I'm very new to Objective-c and IOS development, so please excuse my ignorance!!
I'm stuck when I try to save the route taken, then send/save the location array so I can rebuild the MKpolyline on the next view controller which is opened when the user completes the activity.
I'm not sure whether to save the location array to NSUserDefaults or save it to core data. At the moment I am converting the Array to an NSValue and the saving it to NSUserDefaults like so:
count = [self.locations count];
CLLocationCoordinate2D coordinates[count];
for (NSInteger i = 0; i < count; i++) {
coordinates[i] = [(CLLocation *)self.locations[i] coordinate];
NSValue *locationValue = [NSValue valueWithMKCoordinate:coordinates[i]];
[_locationsArray addObject:locationValue];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:totalDistance forKey:@"totalDistance"];
[defaults setObject:_locationsArray forKey:@"mapOverlay"];
// [defaults setDouble:_totalTime forKey:@"totalTime"];
[defaults setObject:avgSpeedToBeSaved forKey:@"averageSpeed"];
[defaults setObject:totalCalories forKey:@"totalCalories"];
[defaults synchronize];
Is this the right way to do this? And how do I rebuild the locations Array.
If anyone could point me in the right direction it would be greatly appreciated.
I've now changed my code to what was suggested by manecosta to rebuild the CLLocationCoordinates to create an MKPolyline, but my issue now is that the array is Null from where I start to convert into an NSValue. I am unable to figure out why this is, is there something wrong with the way I'm building LocationsArray in the first place?