Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将CLLocationCoordinates 2D转换为NSValue_Ios_Objective C_Cllocation - Fatal编程技术网

Ios 将CLLocationCoordinates 2D转换为NSValue

Ios 将CLLocationCoordinates 2D转换为NSValue,ios,objective-c,cllocation,Ios,Objective C,Cllocation,我只是想将CLLocationCoordinates转换成NSValue以用于稍后在我的应用程序中带回的数组。这是我的密码: NSUInteger count = [self.locations count]; CLLocationCoordinate2D coordinates[count]; for (NSInteger i = 0; i < count; i++) { coordinates[i] = [(CLLocation *)self.loc

我只是想将
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);
    }
nsuiger count=[self.locations count];
CLLocationCoordinate2D坐标[计数];
对于(NSInteger i=0;i
但是,
NSLog
显示数组中填充了(空)值。我不确定哪里出了问题,有人给我指出了正确的方向?

试试:

NSValue *locationValue = [NSValue valueWithBytes:&coordinates[i] objCType:@encode(CLLocationCoordinate2D)];

我在
坐标
数组中看不到任何需要。你可能没有草签。
尝试:


您好,您可以通过如下操作将CLLocationCoordinates 2D转换为NSValue,但必须检查坐标是否包含任何值

NSValue *value = [NSValue valueWithMKCoordinate:coordinate];

谢谢

可能是您没有初始化阵列。这就是为什么当你记录它时它是零

_locationsArray = [[NSMutableArray alloc] init];

检查计数是否不是0。使用NSValue value=[NSValue valueWithMKCoordinate:coordinate]将CLLocationCoordinate2D转换为NSValue时;它迫使您将*MapKit.framework包含到项目中,如果您想避免它,请使用NSValue*value=[NSValue-valueWithBytes:&coordinates-objCType:@encode(CLLocationCoordinate2D)]提出的解决方案;
_locationsArray = [[NSMutableArray alloc] init];