title: iPhone Mapkit adding custom image and pins to annotations
body: <p>I am trying to change the pin colour from the default red to a custom image but whatever I am trying just isn't working.</p>
  
  <p>I have downloaded the sample code from this website: </p>
  
  <p><a href="http://icodeblog.com/2009/12/21/introduction-to-mapkit-in-iphone-os-3-0/" rel="nofollow">http://icodeblog.com/2009/12/21/introduction-to-mapkit-in-iphone-os-3-0/</a></p>
  
  <p>The code works on it's own but when I import the annotation classes into my code, they do not work and I have no idea why. I have also tried a number of different methods from other sites but I can't even get the pin colour to change.</p>
  
  <p>My project has 4 tabs and the MapView is on one of the tabs. When I select it, it parses a JSON string and adds the separate annotations onto the map. i have the title and subtitle showing up when I click on the pin, but cannot change the colour or image.</p>
  
  <p>Here is how I add my annotations - MapAnnotation follows MKAnnotation:</p>
  
  <pre><code>MapAnnotation *ann = [[MapAnnotation alloc] initWithCoordinate:newCoord];
      ann.title = [locationDictionary objectForKey:@"name"];
      ann.subtitle = [locationDictionary objectForKey:@"name"];
  
      [mapView addAnnotation:ann];
      [ann release]
  </code></pre>
  
  <p>Here is how I try and attempt to change the colour - I have MapView.delegate=self in the view controller:</p>
  
  <pre><code>- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id &lt;MKAnnotation&gt;)annotation{
  MKPinAnnotationView *pin = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:[annotation title]];
  
  if (pin == nil) {
      pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:[annotation title]] autorelease];
  }else {
      pin.annotation = annotation;
  }
  
  pin.pinColor = MKPinAnnotationColorGreen;
  pin.animatesDrop = YES;
  pin.canShowCallout = TRUE;
  return pin;
  </code></pre>
  
  <p>}</p>
  
  <p>I get the annotations to appear with title and subtitle, just not green markers. They're always red wether I use colours or images. If anyone could help me out, that would be great! </p>
  
  <p>Thanks</p>
  
  <p>EDIT:</p>
  
  <p>The mapView delegate is assigned in the viewDidLoad method. I also add an Overlay to a certain part of the map. This is working fine, I have also taken it out and tried it without that incase it was causing a problem but it still didn't fix it.</p>
  
  <pre><code>- (void)viewDidLoad {
  [super viewDidLoad];
  
  MKCoordinateRegion cordRgn;
  
  LusuAppAppDelegate *delegate =[[UIApplication sharedApplication]delegate];
  
  if (delegate.CurrentLocation == 0) {
      cordRgn.center.latitude = (CENTRE_OF_POSITION_2_LAT);
      cordRgn.center.longitude = (CENTRE_OF_POSITION_2_LON);
      delegate.CurrentLocation = 1;
  }else if (delegate.CurrentLocation == 1) {
      cordRgn.center.latitude = (CENTRE_OF_POSITION_1_LAT);
      cordRgn.center.longitude = (CENTRE_OF_POSITION_1_LON);  
      delegate.CurrentLocation = 0;
  }
  
  cordRgn.span.latitudeDelta = 0.009f;
  cordRgn.span.longitudeDelta = 0.009f;
  
  
  self.locationManager = [[CLLocationManager alloc] init];
  locationManager.delegate = self;
  locationManager.desiredAccuracy = kCLLocationAccuracyBest;
  
  [locationManager startUpdatingLocation];
  [locationManager startUpdatingHeading];
  
  //add overlay
  MKRasterOverlay *overlay = [[MKRasterOverlay alloc] init];
  [overlay setCoordinate:CLLocationCoordinate2DMake(54.005508, -2.780507)];
  
  MKMapRect mkrect;
  MKMapPoint mkpointa, mkpointb;
  mkrect.origin = MKMapPointForCoordinate(CLLocationCoordinate2DMake(54.016964, -2.794862));
  mkpointa = MKMapPointForCoordinate(CLLocationCoordinate2DMake(54.016964, 2.000000));
  mkpointb = MKMapPointForCoordinate(CLLocationCoordinate2DMake(54.001447, 2.013770));
  mkrect.size.width = mkpointb.x - mkpointa.x;
  mkrect.size.height = mkpointb.y - mkpointa.y;
  overlay.boundingMapRect = mkrect;
  
  mapView.delegate = self;
  
  [mapView addOverlay:overlay];
  [mapView setRegion:cordRgn animated:NO];
  [self.mapView setShowsUserLocation:YES];
  
  [self doAnnotations];
  </code></pre>
  
  <p>}</p>
  
  <p>The doAnnotations function is the code shown above but in a loop. Thanks again for your help.</p>