にユーザーの場所 (青い点) と注釈があり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
}