NSInvalidArgumentException原因: - [CLLocation distanceFromLocation:]

时间:2012-08-14 13:12:00

标签: iphone objective-c ios ios-3.x

我有这个代码只能获得半径10公里范围内的咖啡馆:

for (NSString *ndlog in log) {
    NSString *name = [names objectAtIndex:i];
    NSString *city = [citys objectAtIndex:i];
    NSString *chain = [chains objectAtIndex:i];
    NSString *street = [streets objectAtIndex:i];
    NSString *ndlig = [lig objectAtIndex:i];
    dlog = [ndlog doubleValue];
    dlig = [ndlig doubleValue];
    NSLog(@"%@,%@,%@,%@,%f,%f,%@,%@", name, city, chain, street, dlog, dlig, ndlog, ndlig);
    CLLocation *location = [[CLLocation alloc] initWithLatitude:dlog longitude:dlig];
    double meters = [userLocation distanceFromLocation:location];
    if (meters < 10000) {
        NSString *data = [NSString stringWithFormat:@"%@,%@,%@,%@", name, city, chain, street];
        [tableData addObject:data];
    }
    i++;
}

它在iOS模拟器上运行但在iPhone 2G上崩溃。 (iOS 3.1.3)

我的代码中哪些不正确?

1 个答案:

答案 0 :(得分:2)

方法distanceFromLocation仅适用于iOS 3.2及更高版本。来自the documentation

  

适用于iOS 3.2及更高版本。在CLLocation中声明。

我猜你的模拟器是iOS的新版本。