Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Positioning a custom MKAnnotationView

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.

like image 748
Darren Avatar asked Dec 12 '12 20:12

Darren


1 Answers

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);
like image 101
Vladimir Avatar answered Nov 15 '22 12:11

Vladimir