1110
1110

Reputation: 6839

Bottom of the custom image for MKAnnotation is not positioned right (size issue)

I have a little problem.
I implemented viewForAnnotation to render custom image for my pin on map.
But it seams that there is something wrong with image.

With standard phone pin icons it works fine but with custom image as you can see bottom of the pin is not where it should be.

Bottom of the pin should be at the end of the red line.
I suppose that there must be some sizing issue.

Can somebody tell me what size should I use when creating custom image for pin?

enter image description here

Upvotes: 2

Views: 800

Answers (2)

Jason Harris
Jason Harris

Reputation: 71

Try this code below. it places a pin using the delegate method.

    - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
    {
        MKAnnotationView *annotationView = [[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"annotationReuse"];
        UIImage *pinImage = [UIImage imageNamed:@"pi-image.png"];
        annotationView.image = pinImage;
        annotationView.centerOffset = CGPointMake(0, -pinImage.size.height/2);
        return annotationView;
    }

Upvotes: 5

Wain
Wain

Reputation: 119031

See centerOffset.

By default, the center point of an annotation view is placed at the coordinate point of the associated annotation. You can use this property to reposition the annotation view as needed. This x and y offset values are measured in pixels. Positive offset values move the annotation view down and to the right, while negative values move it up and to the left.

Upvotes: 3

Related Questions