Question

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:

  1. Shadows aren't working.

  2. The image I set for the user location pin is off center and looks like this: user location picture

    enter image description here

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.

Was it helpful?

Solution

In terms of the image being off center, two thoughts:

  1. I generally use MKAnnotationView when using my own images for annotations, not MKPinAnnotationView. When I tried using MKPinAnnotationView, my images were no longer centered.

  2. If worst comes to worst, you can play with the centerOffset property. I don't think you should need to if you use MKAnnotationView.

Regarding your shadow:

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

  2. 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 MKAnnotationView images, and it works fine. Can you share your rounding algorithm with us?

  3. 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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top