将CLLocationCoordinates2D转换为NSValue [英] Converting CLLocationCoordinates2D into an NSValue
本文介绍了将CLLocationCoordinates2D转换为NSValue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想将 CLLocationCoordinates
转换为 NSValue
,以便在稍后带回的数组中使用我的应用。这是我的代码:
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);
}
然而 NSLog
显示数组填充(Null)值。我不确定我在哪里出错,有人指出我正确的方向?
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?
推荐答案
我没有看到坐标
数组中的任何需要。你可能没有初始化它。
尝试:
I didn't see any need in coordinates
array. And you probably didn't initialised it.
Try:
_locationsArray = [NSMutableArray array];
for (CLLocation *location in self.locations) {
NSValue *locationValue = [NSValue valueWithMKCoordinate: location.coordinate];
[_locationsArray addObject:locationValue];
NSLog(@"location = %@", _locationsArray);
}
这篇关于将CLLocationCoordinates2D转换为NSValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文