我在使用该distanceFromLocation
方法时遇到问题,它总是返回零。
这是我的代码片段:
NSArray *arrATMItem = [arrATMs objectAtIndex:indexPath.row];
cell.textLabel.text = [arrATMItem objectAtIndex:0];
float lat = [[arrATMItem objectAtIndex:1] floatValue];
float lon = [[arrATMItem objectAtIndex:2] floatValue];
CLLocation *branchLoc = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
CLLocationDistance dist = [currentLocation distanceFromLocation:branchLoc];
NSLog(@"distance = %d",dist);
cell.detailTextLabel.text = [[NSString alloc] initWithFormat:@"%d m", dist];
我还检查了branchLoc
andcurrentLoc
实例是否具有正确的值。
这是一个示例值branchLoc
:
纬度:-6.17503957 经度:106.79891717
的值currentLoc
是:
纬度:-6.17603957 经度:106.79891717
这些branchLoc
值是从 plist 文件中检索的,并且currentLoc
是从locationUpdate
我的委托文件中定义的 CLLocation 方法上的 CLLocation 类中获得的。
我尝试使用 %f ,它也返回类似 0.00000 的值。
知道我做错了什么吗?
谢谢