我试图添加到一个可变数组,但无法弄清楚这一点。如果 double 数据类型与 id 不兼容,则会引发错误。问题是如何转换距离并将其存储在数组中。
for (int i = 0; i < _getAllLocations.count; i++) {
uscInfo *entity = [_getAllLocations objectAtIndex:i];
NSNumber *numlat=[[NSNumber alloc] initWithDouble:[entity.Latitude doubleValue]];
NSNumber *numlon=[[NSNumber alloc] initWithDouble:[entity.Longitude doubleValue]];
NSLog(@"%d",[_getAllLocations count]);
la=[numlat doubleValue];
lo=[numlon doubleValue];
CLLocation *currentLocation = [[CLLocationalloc]initWithLatitude:lalongitude:lo];////here put your destination point
//NSLog(@"New Location:%@", newLocation);
CLLocationDistance distance = [newLocation distanceFromLocation:currentLocation];
NSLog(@"%@ (%@) %4.0f km from current location",entity.EntityNo, entity.EntityName, distance);
NSLog(@"%@",currentLocation);
我正在尝试将“距离”存储在数组“locationDistance”中
感谢您的帮助,我对 iOS 以及一般编程还是新手。
最佳答案
(您确实应该包含不起作用的代码 - 在本例中为实际的 addObject:
代码。)
但我可以告诉你,问题是你可能试图向数组添加一个裸的 CLLocationDistance,这将不起作用,因为它不是一个对象。它的 typedef
为 double
,因此您需要使用 [NSNumber numberWithDouble:distance]
来包装它。
关于ios - 在 cllocationdistance 中转换数据时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10605620/