在cllocationdistance中转换数据时出现问题 [英] problems converting data in cllocationdistance
问题描述
我正在尝试添加到可变数组中,但无法弄清楚.对于不兼容的数据类型,将引发double到id的错误.问题是如何转换距离并将其存储在数组中.
Im trying to add to a mutable array and can not figure this out. Throws error for incompatable data types double to id. question is how do i convert distance and store it in my array.
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"中
I am trying to store "distance" in my array "locationDistance"
感谢您的帮助,我仍然是iOS以及编程方面的新手.
thanks for any help, I am still new to iOS as well as programming in general.
推荐答案
(您确实应该包含不起作用的代码-在本例中为实际的addObject:
代码.)
(You really should include the code that's not working - in this case the actual addObject:
code.)
但是我可以告诉你问题是您可能试图在数组中添加一个裸露的CLLocationDistance,因为它不是对象,所以无法正常工作.它被typedef
命名为double
,因此您需要使用例如[NSNumber numberWithDouble:distance]
对其进行换行.
But I can tell you that the problem is you are likely trying to add a naked CLLocationDistance to the array, which won't work as it's not an object. It's typedef
'd as a double
so you need to wrap it using, e.g., [NSNumber numberWithDouble:distance]
.
这篇关于在cllocationdistance中转换数据时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!