我试图添加到一个可变的数组,但无法解决这个问题。对于不兼容的数据类型double to 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);我尝试将"distance“存储在数组"locationDistance”中
谢谢你的帮助,我对iOS和一般的编程都还是个新手。
发布于 2012-05-16 01:29:25
(您确实应该包括不起作用的代码-在本例中是实际的addObject:代码。)
但我可以告诉你,问题是你可能正在尝试向数组中添加一个裸CLLocationDistance,这不会起作用,因为它不是一个对象。它是typedef'd格式的double,所以你需要用[NSNumber numberWithDouble:distance]来包装它。
https://stackoverflow.com/questions/10605620
复制相似问题