So I’m really confused. I used:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString* AnnotationIdentifier = @"Annotation";
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if (!pinView) {
MKPinAnnotationView *customPinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
if (annotation == mapView.userLocation){
customPinView.image = [UIImage imageNamed:@"303761_4417778996801_94858213_n.jpg"];
[customPinView.layer setMasksToBounds:NO];
[self setRoundedView:customPinView toDiameter:kPictureDiameter];
[customPinView.layer setBorderColor:[UIColor whiteColor].CGColor];
[customPinView.layer setBorderWidth:5.0f];
[customPinView.layer setShadowColor:[UIColor blackColor].CGColor];
[customPinView.layer setShadowOpacity:1.0f];
[customPinView.layer setShadowRadius:20.0f];
[customPinView.layer setShadowOffset:CGSizeMake(0, 0)];
[customPinView setBackgroundColor:[UIColor whiteColor]];
}
return customPinView;
} else {
pinView.annotation = annotation;
}
return pinView;
}
to add my own image to the user location pin. And that works. There’s two problems though:
-
Shadows aren’t working.
-
The image I set for the user location pin is off center and looks like this:
user location picture
I’ve tried fooling around with CGRect, CGPoint, setting the frame, center ect (although I haven’t tried changing the bounds as of yet) and nothing changes.
Any help would be so appreciated.
In terms of the image being off center, two thoughts:
I generally use
MKAnnotationViewwhen using my own images for annotations, notMKPinAnnotationView. When I tried usingMKPinAnnotationView, my images were no longer centered.If worst comes to worst, you can play with the
centerOffsetproperty. I don’t think you should need to if you useMKAnnotationView.Regarding your shadow:
A shadow radius of 20 is so great, that it’s so diffuse that you can barely see it. I could barely make it out when I used 20. It was starting to become more visible at 10, and even more so at 5. I don’t think this is the real problem here, but as you start to experiment, use a number low enough here so you can clearly see the shadow.
Having said that, I don’t think that’s the problem. I’m suspicious of the image rounding algorithm. Can you try temporarily commenting that out and see if your shadow appears? But I use shadows on my
MKAnnotationViewimages, and it works fine. Can you share your rounding algorithm with us?And if that doesn’t do it, is this image coinciding with an overlay? (i.e. what’s that circle behind the picture). I’d try, again, temporarily removing it and see if that changes the behavior. When I use a
MKCircleView, it works fine, but let’s make sure we’re not doing anything curious there (or with any other drawing routines).