gpt4 book ai didi

ios - 将坐标中的 CLLocation 纬度插入 NSMutableArray

转载 作者:行者123 更新时间:2023-11-29 12:21:40 25 4
gpt4 key购买 nike

我正在做一些愚蠢的事情,但不确定是什么。这是我的代码:

NSMutableArray *latitudes = [[NSMutableArray alloc] init];


NSMutableArray *locationArray = [NSMutableArray array];
for (CLLocation *location in self.allPins) {
Location *locationObject = [NSEntityDescription insertNewObjectForEntityForName:@"Location"
inManagedObjectContext:self.managedObjectContext];

locationObject.timestamp = location.timestamp;
locationObject.latitude = [NSNumber numberWithDouble:location.coordinate.latitude];
locationObject.longitude = [NSNumber numberWithDouble:location.coordinate.longitude];
[locationArray addObject:locationObject];
[latitudes addObject:[NSNumber numberWithFloat: location.coordinate.latitude]];
NSLog(@"here is the array for latitudes count: %d", latitudes.count);
NSLog(@"here is the value for first latitude: %d", latitudes[0]);
}

self.allPins 保存从 CLLocationManager 接收到的所有位置。一旦用户完成移动并想要保存,我运行上面的代码片段将轨迹加载到 CoreData 类中以保存在用户的手机上,并将数据加载到数组中以在线上传数据。我想要一组纬度经度等,但这行不通。虽然我可以将信息很好地插入到我的 CoreData 对象中,但我似乎无法简单地从 CLLocation 坐标中提取 double / float (尝试了两种方法,但我认为它不应该有所作为?)。当我运行以下代码时,我得到了纬度数组的计数,但我得到的值是无意义的:

2015-05-26 15:25:22.934 MileRun[665:196255] here is the value for first latitude: 426649664

最佳答案

您没有打印 NSNumber 的值,但我认为是 NSNumber 的地址(如果不是 426649664 在他的日志中,有人可能会在这里纠正我)。

NSLog(@"here is the value for first latitude: %d", latitudes[0]); 更改为

NSLog(@"这里是第一个纬度的值:%f", latitudes[0].floatValue);

NSLog(@"here is the value for first latitude: %@", latitudes[0]);

更多信息编辑:格式说明符 %d 用于整数。您可以使用对象的格式说明符打印出 NSNumber,即 %@。这将允许您使用 NSLog(@"number = %@", latitudes[0]) 登录并以这种方式获取 NSNumber 的值。

此外,如有疑问,请在代码中设置断点并使用调试器检查数组中的对象。

关于ios - 将坐标中的 CLLocation 纬度插入 NSMutableArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30467403/

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