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 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes! That did the trick. Not sure how I missed this! Thank you.
This answer saved me a lot time. Unfortunately the SIMULATOR has a BUG and even tough I was using the MKPinAnnotationView the simulator was showing me the correct image what I set, only the device did not show me the Image. I drove crazy till I found this post. Thanks again. And be careful, THE SIMULATOR IS YOUR BIGGEST ENEMY ! :-)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.