title: How can I get coordinates of taped pin to calculate distance between user location and pin
body: <p>I have a lot of annotations on my mapview and I need to calculate distance from user location to taped annotation. How can that be done?</p>
  
  <p>MyAnnotation</p>
  
  <pre><code>- (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id &lt;MKAnnotation&gt;)annotation
  {
  
      if (![annotation isKindOfClass:[MyAnnotation class]])
      {
          return nil;
      }
  
      static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
  
      MKAnnotationView *pinView = [aMapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
  
      if (pinView == nil)
      {
          pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
          pinView.canShowCallout = YES;
          pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeInfoLight];
  
  
      }
      else
          pinView.annotation = annotation;
  
      MyAnnotation *myAnn = (MyAnnotation *)annotation;
      pinView.image = [UIImage imageNamed:myAnn.icon];
  
      return pinView;
  
  }
  </code></pre>
  
  <p>To calculate I use</p>
  
  <pre><code>- (void)locationManager:(CLLocationManager *)manager
      didUpdateToLocation:(CLLocation *)newLocation
             fromLocation:(CLLocation *)oldLocation
  {
  
      CLLocation *pinLocation = [[CLLocation alloc] initWithLatitude:37.322998 longitude:-122.032182];
  
      NSLog(@"New Location:%@", newLocation);
      CLLocationDistance distance = [newLocation distanceFromLocation:pinLocation];
      NSLog(@"Distance to pin %4.0f", distance);
  
  }
  </code></pre>
  
  <p><strong>But how can I get pin coordinates automatically when annotation taped?</strong></p>
  
  <p>EDIT:</p>
  
  <pre><code>- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view 
  calloutAccessoryControlTapped:(UIControl *)control
  {
      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];
      NSLog(@"Distance to pin %4.0f", distance);
  
  }
  </code></pre>