CLLocation distanceFromLocation:返回-1

时间:2016-02-02 08:01:52

标签: ios objective-c iphone cocoa-touch cllocation

我有一个函数可以找到距用户位置最近的store,并从距离最近的allStores数组中排序twentyClosestStores。 之后需要将索引0-19上的商店(20个壁橱存储到用户的位置)并将其添加到location1数组。

问题是:当我尝试使用location2方法测量distanceFromLocation:-1之间的延迟时,它会返回-(void)sortClosestStores { [self.allStores sortUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) { CLLocation *location1=[[CLLocation alloc] initWithLatitude:((Store*)obj1).geoPoint.latitude longitude:((Store*)obj1).geoPoint.longitude]; CLLocation *location2=[[CLLocation alloc] initWithLatitude:((Store*)obj2).geoPoint.latitude longitude:((Store*)obj2).geoPoint.longitude]; float dist1 =[location1 distanceFromLocation:self.locationManager.location]; //Returns -1 float dist2 = [location2 distanceFromLocation:self.locationManager.location]; //Returns -1 if (dist1 == dist2) { return NSOrderedSame; //Being called because both dist1 and dist 2' value is -1 } else if (dist1 < dist2) { return NSOrderedAscending; } else { return NSOrderedDescending; } }]; if (self.twentyClosestStores==nil) { self.twentyClosestStores=[NSMutableArray array]; } self.twentyClosestStores=[NSMutableArray array]; for (int i = 0; i < 20; i++) { [self.twentyClosestStores addObject:[self.allStores objectAtIndex:i]]; } } 而我无法理解为什么。< / p>

我的代码:

$var = "<html>Hi.. <strong>how</strong>are <u>you?</u></html>

有人知道为什么它不能正常工作吗?谢谢!

1 个答案:

答案 0 :(得分:0)

这是createUser()

的枚举
NSComparisonResult

-1用于typedef NS_ENUM(NSInteger, NSComparisonResult) {NSOrderedAscending = -1L, NSOrderedSame, NSOrderedDescending};

您可以使用

对数组进行排序
NSOrderedAscending