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];