user1044147
user1044147

Reputation: 108

MKAnnotationView not showing up on the map

I am trying to annotate my map with MKPointAnnotation, like this:

- (void)viewDidLoad
{
    NSLog(@"RootViewController viewDidLoad");

    [super viewDidLoad];

    CLLocationCoordinate2D coord = 
    CLLocationCoordinate2DMake(54.903683,23.895435);

    MKPointAnnotation *toyAnnotation = [[MKPointAnnotation alloc] init];

    toyAnnotation.coordinate = coord;
    toyAnnotation.title = @"Title";
    toyAnnotation.subtitle = @"Subtitle";

    [mapView addAnnotation:toyAnnotation];

    [toyAnnotation release];

}

- (MKAnnotationView *)mapView:(MKMapView *)m 
            viewForAnnotation:(id <MKAnnotation>)annotation
{
    NSLog(@"RootViewController mapView: viewForAnnotation:");
    NSLog(@"%@",annotation);

    MKAnnotationView *pin = [[MKAnnotationView alloc] 
                             initWithAnnotation:annotation 
                             reuseIdentifier:nil];

    pin.enabled = YES;
    pin.canShowCallout = YES;

    return [pin autorelease];
}

Pin fails to appear on the map. RootViewController is a delegate for mapView and thus mapView:viewForAnnotation: method gets called:

2011-11-24 15:04:03.808 App[2532:707] RootViewController mapView: viewForAnnotation:
2011-11-24 15:04:03.810 App[2532:707] <MKPointAnnotation: 0x1885c0>

What am I doing wrong and how to fix this issue?

Upvotes: 6

Views: 5595

Answers (1)

user467105
user467105

Reputation:

In viewForAnnotation, create an MKPinAnnotationView instead of an MKAnnotationView (for which you have to set the image).

Although for a default pin annotation view, you don't need to implement the delegate method at all.

Upvotes: 21

Related Questions