私はユーザーの場所(青い点)と注釈をmapView
に持っています。注釈が選択されている場合、テキストをdistLabel
に設定しています - 「%までの距離は4.0fmです」。ユーザーが移動すると、そのテキストラベルをどのように更新できますか?ユーザーが移動したときにユーザーの場所から注釈までの距離を計算する方法
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
}
グレート答え!ありがとうございました! –