views:

75

answers:

1

I figured that using my own custom pin image for annotations would be super easy. But, I have never been able to get it to work, and I have no idea why! I am simply using:

Annotation *anno = [[[Annotation alloc] init] autorelease];
        anno.coordinate = ridesMap.userLocation.location.coordinate;
        anno.title = @"Current Location";
        anno.subtitle = [NSString stringWithFormat:@"%f, %f", anno.coordinate.latitude, anno.coordinate.longitude];

        static NSString *defaultPinID = @"LocationIdentifier";
        MKPinAnnotationView *pinView = (MKPinAnnotationView *)[ridesMap dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if (pinView == nil){
            pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:anno reuseIdentifier:defaultPinID] autorelease];
        }

        pinView.image = [UIImage imageNamed:@"custom_pin.png"];
        pinView.opaque = NO;
        pinView.canShowCallout = YES;
        pinView.draggable = NO;

        pinView.annotation = anno;
        NSLog(@"Adding current location annotation");

        return pinView;

I assumed that this should work, as a UIImage is what it is wanting, and I do have the custom_pin.png file in my project.

It never uses my image, but just the standard red pin. What am I doing wrong here?

+1  A: 

From the docs:

The MKPinAnnotationView class provides a concrete annotation view that displays a pin icon like the ones found in the Maps application.

In other words, a MKPinAnnotationView will ignore the image property and always display a pin. Use a regular MKAnnotationView instead.

Ole Begemann
Yes! That did the trick. Not sure how I missed this! Thank you.
Nic Hubbard