1

我在使用该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];

我还检查了branchLocandcurrentLoc实例是否具有正确的值。

这是一个示例值branchLoc

纬度:-6.17503957 经度:106.79891717

的值currentLoc是:

纬度:-6.17603957 经度:106.79891717

这些branchLoc值是从 plist 文件中检索的,并且currentLoc是从locationUpdate我的委托文件中定义的 CLLocation 方法上的 CLLocation 类中获得的。

我尝试使用 %f ,它也返回类似 0.00000 的值。

知道我做错了什么吗?

谢谢

4

1 回答 1

0

尝试对纬度和经度使用双精度(或 CLLocationDegrees)。

于 2011-03-31T12:46:42.577 回答