我有一个用户位置(蓝点)和注释mapView
。选择注释时,我将文本设置为distLabel
- “到点的距离 %4.0f m.”。用户移动时如何更新该文本标签?
didSelectAnnotationView:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
CLLocation *pinLocation =
[[CLLocation alloc] initWithLatitude:
[(MyAnnotation*)[view annotation] coordinate].latitude
longitude:
[(MyAnnotation*)[view annotation] coordinate].longitude];
CLLocation *userLocation =
[[CLLocation alloc] initWithLatitude:
self.mapView.userLocation.coordinate.latitude
longitude:
self.mapView.userLocation.coordinate.longitude];
CLLocationDistance distance = [pinLocation distanceFromLocation:userLocation];
[distLabel setText: [NSString stringWithFormat:@"Distance to point %4.0f m.",
distance]];
}
我知道有一个功能didUpdateToLocation
,但我该如何使用它didSelectAnnotationView
呢?
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
//Did update to location
}