gpt4 book ai didi

ios - 将 CLLocationCoordinates2D 转换为 NSValue

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:06:14 26 4
gpt4 key购买 nike

我只是想将 CLLocationCoordinates 转换为 NSValue 以用于稍后在我的应用程序中带回的数组。这是我的代码:

  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) 值。我不确定这里哪里出了问题,有人指出我正确的方向吗?

最佳答案

我没有看到任何需要 coordinates 数组。你可能没有初始化它。尝试:

_locationsArray = [NSMutableArray array];
for (CLLocation *location in self.locations) {
NSValue *locationValue = [NSValue valueWithMKCoordinate: location.coordinate];
[_locationsArray addObject:locationValue];
NSLog(@"location = %@", _locationsArray);
}

关于ios - 将 CLLocationCoordinates2D 转换为 NSValue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22113675/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com