2012-08-14 109 views
0

我有这样的代码来获得仅10公里半径范围内的咖啡馆:NSInvalidArgumentException原因: - [CLLocation distanceFromLocation:]

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++; 
} 

其上运行的iPhone模拟器,但崩溃的iPhone 2G。 (iOS 3.1.3)

什么是不正确的在我的代码?

回答

2

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

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

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

相关问题