I'm simply trying to convert CLLocationCoordinates
into an NSValue
to be used in an array brought back later in my app. Here is my code:
NSUInteger 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];
NSLog(@"location = %@", _locationsArray);
}
However the NSLog
displays that the array is filled with (Null) values. I'm not sure where I have gone wrong here, an someone point me in the right direction?
Hi you can convert the CLLocationCoordinates2D into an NSValue by doing like below but have you check the coordinate contains any value or not once.
Thanks
Try:
I didn't see any need in
coordinates
array. And you probably didn't initialised it. Try:It can be that you didn't initialize your array. That's why it's nil when you log it.