我必须做一个项目,在该项目中我必须计算从我的位置(由 gps 检测到)到许多位置在 plist 文件中的餐厅的距离,然后在列表视图中显示距离作为餐厅名称的副标题.
我知道CLLocationDistance
并且我写了一个函数,它是:-
-(double)distanceBetPoints
{
CLLocation *user = [[CLLocation alloc] initWithLatitude:locationManager.location.coordinate.latitude longitude:locationManager.location.coordinate.longitude];
CLLocationDistance distance = [user distanceFromLocation:restaurant.location];
return distance;
}
这里位置管理器正在确定我的位置,并且restaurant.location
是 plist 文件中的位置条目。
我在单元格配置中写了以下内容:-
NSString *d = [NSString stringWithFormat:@"%@",[mapVC.distanceBetPoints]];
cell.detailTextLabel.text = [@"%@",[d]];
这mapVC
是我的mapVC
类对象,其中存在距离计算方法,这两行都给了我预期标识符的错误。
另外,我如何为每家餐厅分别计算并在 tableview 中显示?我必须将值存储在数组中吗?如果是,那么我应该把我的方法放在哪里,我应该在哪里调用它,以便为每家餐厅计算它并存储在一个数组中。