title: How to add an image for each customized annotation on MapView?
body: <p>I have a class of <code>Picture</code> which contains <code>latitude</code> and <code>longitude</code> and <code>image</code> of each location. I want to add them as annotation to the <code>MapView</code> and show its image instead of pin for those locations.</p>
  
  <p>I have a customized annotation which is:</p>
  
  <pre><code>@interface Annotation : MKAnnotationView  &lt;MKAnnotation&gt;
  
  @property (nonatomic,assign) CLLocationCoordinate2D coordinate;
  @property (nonatomic,copy) NSString *title;
  @property (nonatomic,copy) NSString *subtitle;
  @property (nonatomic,retain) UIImage *image;
  
  
  @end
  </code></pre>
  
  <p>And</p>
  
  <pre><code>@implementation Annotation 
  
  @synthesize title,subtitle,coordinate,image;
  
  
  @end
  </code></pre>
  
  <p>Now in main code I am trying this:</p>
  
  <pre><code>CLLocationCoordinate2D location;
  Annotation *myAnn;
  
  for(Pictures *pic in picturesFromDB)
  {
  myAnn = [[Annotation alloc] init];
  location.latitude = [pic.langT doubleValue];
  location.longitude = [pic.longT doubleValue];
  myAnn.coordinate = location;
  myAnn.title = pic.descript;
  
  
  myAnn.image = [UIImage imageWithData:pic.image]; //Not sure about this line!
  
  
  [self.mapView addAnnotation:myAnn];
  </code></pre>
  
  <p>}</p>
  
  <p>Do I still need the delegate and must call "viewForAnnotation"? Because it did not work, I did this for delegate:</p>
  
  <pre><code>- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id &lt;MKAnnotation&gt;)annotation
  {
      // If it's the user location, just return nil.
      if ([annotation isKindOfClass:[MKUserLocation class]])
          return nil;
  
      // Handle any custom annotations.
      if ([annotation isKindOfClass:[Annotation class]])
      {
          // Try to dequeue an existing pin view first.
          MKAnnotationView *pinView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomPinAnnotationView"];
          if (!pinView)
          {
             // If an existing pin view was not available, create one.
              pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotationView"];
              //pinView.animatesDrop = YES;
              pinView.canShowCallout = YES;
  
              pinView.image = [UIImage imageNamed:@"image.png"];            
              pinView.calloutOffset = CGPointMake(0, 4);
  
          } else {
  
              pinView.annotation = annotation;
          }
          return pinView;
      }
      return nil;
  }
  </code></pre>
  
  <p>This is working fine but adding same image to all the locations. But I have a specific image to show instead of <code>image.png</code> above for each location.</p>
  
  <p>Number of location is variable and also dynamic.</p>
  
  <p>How can I pass that image to the delegate. I tried to find the image field in the passed annotation, but it does not exist! I appreciate any suggestion.</p>