Search code examples
iphoneobjective-cmkannotationmkannotationview

setting up Image in MKAnnotationPinView


I have the following code inside the delegate:

     - (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)anAnnotation 
{
    MKPinAnnotationView *pin = (MKPinAnnotationView *) [map dequeueReusableAnnotationViewWithIdentifier: @"RoutePin"];
    if (pin == nil)
    {
        if ([anAnnotation isKindOfClass:[RouteMapAnnotation class]])
        {
            RouteMapAnnotation *theAnnotation = (RouteMapAnnotation *)anAnnotation;
            if (theAnnotation.identifier == @"routePin")
            {
                //NSLog(@"TESTING PART III");
                MKPinAnnotationView *startAnnotationPin = [[MKPinAnnotationView alloc] initWithAnnotation:anAnnotation reuseIdentifier:@"RoutePin"];
                UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
                startAnnotationPin.canShowCallout = YES;
                startAnnotationPin.animatesDrop = YES;

                startAnnotationPin.rightCalloutAccessoryView = rightButton;
                startAnnotationPin.pinColor = MKPinAnnotationColorRed;
                return startAnnotationPin;
            }
            else if (theAnnotation.identifier == @"finishPin")
            {
                NSLog(@"CREATING FINISH FLAG PRIOR");
                MKPinAnnotationView *finishAnnotationPin = [[MKPinAnnotationView alloc] initWithAnnotation:anAnnotation reuseIdentifier:@"FinishPin"];
                finishAnnotationPin.canShowCallout = NO;
                finishAnnotationPin.animatesDrop = YES;
                //finishAnnotationPin.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://cdn4.iconfinder.com/data/icons/formula1/f1_png/128/checkered_flag.png"]]];
                finishAnnotationPin.image = [UIImage imageNamed:@"flag_finish"];
                return finishAnnotationPin;

            }
        }
    }
    return nil;
}

However it's not showing the image for the pin on the map. What am I missing??


Solution

  • You should use MKAnnotationView instead of MKPinAnnotationView.

    pin annotation is for pins.