【发布时间】:2013-01-28 07:11:01
【问题描述】:
我想在自定义表格单元格的标签中显示用户当前位置与另一个注释(显示在我的 MapView 上)之间的距离。
每个单元格显示咖啡馆的名称(nameLabel),在下面,我希望它显示与每个咖啡馆的距离(distanceLabel)。
我的 MapViewController.m 使用此代码计算用户当前位置与最近的咖啡馆之间的距离:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
for (MapViewAnnotation *annotation in self.mapView.annotations) {
CLLocationCoordinate2D coord = [annotation coordinate];
CLLocation *userLocation = [[CLLocation alloc] initWithLatitude:coord.latitude longitude:coord.longitude];
annotation.distance = [newLocation distanceFromLocation:userLocation];
CLLocationDistance calculatedDistance = [userLocation distanceFromLocation:userLocation];
annotation.distance = calculatedDistance;
}
我已经设置了我的自定义单元格,我只想知道我应该在我的 TableView 代码 (TableViewController.m) 中添加什么,以便在我的文本标签(称为 distanceLabel)。
例如我该如何完成这条线?
cell.distanceLabel.text =
更新
刚刚尝试添加对我的 TableViewController.h 的引用,但 xcode 不断向我抛出错误“将 'CLLocationDistance' 重新定义为不同类型的符号”。
@class CLLocationDistance;
@property (nonatomic, strong) CLLocationDistance *calculatedDistance;
更新
.h 文件
****更新**
**.m 文件****
【问题讨论】:
标签: objective-c android-mapview tableview cllocation