首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在cllocationdistance中转换数据时出现问题

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

Stack Overflow用户
提问于 2012-05-16 01:09:15
回答 1查看 1.9K关注 0票数 0

我试图添加到一个可变的数组,但无法解决这个问题。对于不兼容的数据类型double to id抛出错误。问题是如何转换距离并将其存储在我的数组中。

代码语言:javascript
复制
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和一般的编程都还是个新手。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-16 01:29:25

(您确实应该包括不起作用的代码-在本例中是实际的addObject:代码。)

但我可以告诉你,问题是你可能正在尝试向数组中添加一个裸CLLocationDistance,这不会起作用,因为它不是一个对象。它是typedef'd格式的double,所以你需要用[NSNumber numberWithDouble:distance]来包装它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10605620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档