3

I have a mapView in my app, and I'm using my own image for the MKAnnotationView, which is the the pin image. Here is my code for setting it.

-(RMAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(RentPin *)annotation{

    static NSString *identifier = @"MyLocation";

    if ([annotation isKindOfClass:[RentPin class]]) {
        RMAnnotationView *annotationView = (RMAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

        if(annotationView == nil){
            annotationView = [[RMAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
            annotationView.enabled = YES;
            annotationView.canShowCallout = NO;
            annotationView.image = [UIImage imageNamed:@"home44.png"];
            annotationView.centerOffset = CGPointMake(-10, -10);
        }else{
            annotationView.annotation = annotation;
        }

        return annotationView;
    }
    return nil;
}

It is working fine and the customized image is also showing properly, but when I pinch the mapView for zooming in/out the map, I noticed that the customized image loses its accuracy on the map. Please have a look the images following.

https://www.dropbox.com/s/irrgmohppf08fzr/image1.png This image shows the pin is at this position, which is quite accurate.

https://www.dropbox.com/s/vvlr4ckk6molqd7/image2.png After I zoomed out the mapView, the pin crossed the street and showing that this address is in the lake....

(Sorry for the links, since I can't post images because of insufficient reputation.)

Anyone could help me regarding this? my pin image is 44x44 and I also tried setting centerOffset of the pin, it cannot dynamically solved this problem in all the zoom levels.

Christopher
  • 731
  • 6
  • 24
  • Also see http://stackoverflow.com/questions/8165262/mkannotation-image-offset-with-custom-pin-image, http://stackoverflow.com/questions/7461474/ios-mapkit-annotation-not-showing-correct-location, etc. –  Jun 18 '14 at 12:11

1 Answers1

5

It's simply the wrong center offset. But be aware that the center offset depends on the type of annotation view you are using. I don't know what RMAnnotationView is. If it's a subclass of MKAnnotationView, the centerOffset should be CGPointMake(0, -imageHeight / 2).

jimpic
  • 5,360
  • 2
  • 28
  • 37