title: iPhone Core Location: DIfferentiate pin for custom pin image
body: <p>I am using</p>
  
  <p><code>- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id &lt;MKAnnotation&gt;) annotation{</code></p>
  
  <p>to draw my own image for a custom pin. I would like to use a different image for different pins. I was wondering how I could differentiate which pin was calling this function.</p>
  
  <pre><code>- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id &lt;MKAnnotation&gt;) annotation{
  
      MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MyPin"];
      annView.canShowCallout = YES;
  
      annView.calloutOffset = CGPointMake(-5, 5);
  
      if ([annView.annotation.title isEqualToString:myLocation]) {
          UIImage *pinImage = [UIImage imageNamed:@"myLocationImage.png"];
          [annView setImage:pinImage];
      } else {
          UIImage *pinImage = [UIImage imageNamed:@"resImage.png"];
          [annView setImage:pinImage];
      }
  
      return annView;
  }
  </code></pre>
  
  <p><strong>EDIT:</strong> Revisiting this for a new project, I realized creating different pin classes was wasteful. A better implementation would be to set the pin type, then read it out of the annotation of the MKAnnotationView. Example below.</p>
  
  <pre><code>- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id &lt;MKAnnotation&gt;) annotation {
  
      MKPinAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"PinID"];
      UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
      [button addTarget:self action:@selector(viewStoreDetails:) forControlEvents:UIControlEventTouchDown];
  
      pin.rightCalloutAccessoryView = button;
      pin.canShowCallout = YES;
      pin.calloutOffset = CGPointMake(-5, 5);
  
      Annotation *a = (Annotation *)pin.annotation;
  
      int i = a.locationType;
  
      switch (i) {
          case RETAIL:
              pin.image = [UIImage imageNamed:@"pin_retail.png"];
              break;
          case OUTLET:
              pin.image = [UIImage imageNamed:@"pin_outlet.png"];
              break;
          case COMING_SOON:
              pin.image = [UIImage imageNamed:@"pin_coming_soon.png"];
              break;
          case MY_LOCATION:
              pin.image = [UIImage imageNamed:@"pin_my_location.png"]; 
              break;
              pin.image = [UIImage imageNamed:@"pin_retail.png"];
          default:
              break;
      }
  
      return [pin autorelease];
  }
  </code></pre>