MKAnnotationView not showing up on the map
Asked Answered
A

1

6

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?

Ali answered 24/11, 2011 at 13:32 Comment(0)
M
21

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.

Mogilev answered 24/11, 2011 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.