Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the image's origin of map annotation view?

Tags:

The regular annotation pin's origin is in the middle of the bottom so, the pin always point to the same place.

But when I add my custom image, its origin is the center of the image, so every zoom in or out, the bottom of my image point to a different place.

enter image description here

Here my pin is supposed to point to the center of paris BUT

enter image description here

but when I zoom in, the bottom of my pin isn't pointing to the center of Paris.

I'm trying with the CGRect.origin but didn't get anything useful.

Here is my code:

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    MKAnnotationView * customPinView = [[MKAnnotationView alloc] init];
    UIImage * img = [UIImage imageNamed:@"waterPin.png"] ;
    CGRect resizeRect;
    resizeRect.size.height = 40;
    resizeRect.size.width = 40;
    resizeRect.origin = (CGPoint){0.0f, 0.0f};
    UIGraphicsBeginImageContext(resizeRect.size);
    [img drawInRect:resizeRect];
    UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    customPinView.image = resizedImage;
    return customPinView;
}