Positioning a custom MKAnnotationView
Asked Answered
D

1

9

I create a custom MKAnnoationView as follows:

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
    MKAnnotationView* customPinView = [[MKAnnotationView alloc]
                                           initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];

    UIImage *pinImage = [PowerPlantAnnotation getAnnotationImageForEnergySource:((PowerPlantAnnotation*)annotation).energySource];
    customPinView.image = pinImage;
    return customPinView;
}

I get the image that I want positioned more or less in the right spot, but not quite. My image looks like this:

enter image description here

I want the bottom point of the tear drop to point to my annotation map coordinate, like the standard pin view points to the map coordinate. How can I accomplish this? Currently it looks a bit more like my image is centered on the map coordinate.

Dharna answered 12/12, 2012 at 20:28 Comment(0)
P
15

By default annotation view center is placed at the annotation coordinate. To adjust view position set its centerOffset property:

annotationView.centerOffset = CGPointMake(0.0f, -annotationViewHeight/2);
Parts answered 12/12, 2012 at 20:48 Comment(1)
in this case. the center of the view aligns at the exact coordinate position. The base of the pin of should be at the coordinate for accuracy.Belicia

© 2022 - 2024 — McMap. All rights reserved.