Problem with iPhone PIN

I have an application that uses the iphone card set. It shows a set of standard contacts. Now I switch to custom images for contacts (using MKMapViewDelegate)

The problem is that user contacts are not centered to the right - user output points to a place next to the original.

The question is how the iphone works with a custom pin. For example: suppose you have an image for a 50x50 pixel pin. And we have a global coordinate (long, lat): XY

How will the image be in the center of the iphone?

Thank you

+7
source share
2 answers

If you assign your own image to the image property. When an annotation is displayed, the image is displayed centered on the coordinate of the target map. If you do not want the image centered on the map coordinate, you can use the centerOffset property to move the center point horizontally and vertically in any direction.

Thus, a custom image is displayed only in the center of your target coordinates.

MKAnnotationView* aView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MyCustomAnnotation"] autorelease]; aView.image = [UIImage imageNamed:@"myimage.png"]; aView.centerOffset = CGPointMake(10, -20); 

Source: apple class link for MKMapView

+9
source

The solution is to set the center offset in the mapView delegate and not in the annotation view:

 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { static NSString* const kPinIdentifier = @"pinidentifier"; PinAnnotationView* customPinView = [[[PinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:kPinIdentifier] autorelease]; customPinView.canShowCallout = NO; // Here !! customPinView.centerOffset = CGPointMake(0, -21.5f); return customPinView; } 
+6
source

All Articles