ios - 在 cllocationdistance 中转换数据时出现问题

标签 ios ipad nsmutablearray mkmapview cllocationdistance

我试图添加到一个可变数组,但无法弄清楚这一点。如果 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,这将不起作用,因为它不是一个对象。它的 typedefdouble,因此您需要使用 [NSNumber numberWithDouble:distance] 来包装它。

关于ios - 在 cllocationdistance 中转换数据时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10605620/

相关文章:

ios - 从 iOS 创建 getStream 用户

ios - 为什么 UIView 的框架没有在 ViewDidLayoutSubviews 中更新?

iphone - 在 NSObject 类中显示一个 UIAlertView

ios - 将数组和字符串传递给自定义 UIView 类(子类)(iOS)

iphone - NSArray - 检查对象是否在数组中?

ios - 如何根据主数组中的长度对数组进行排序

ios - 快速执行 Segue 到另一个 Storyboard

ios - 使用 Swift 以编程方式自定义 UITableViewCell

iphone - 没有平滑的图像查看器

iPad 上的 Java 网络启动