1

Please let me know how to make an image appear at a centre point. Let me elaborate. I have a custom image on MapPin but the image seems to be something like this

enter image description here

If you closely look at it, the pin falls on the correct lat and long but the centre of the the image that is the rounded part falls on the lat and long.Due to which the lat long seems to be at a different position.(See the pin base). But what we want instead is the pin base to fall on the position (Lat and Long). Something like this.. (Refer the second image) Please don't tell me to change the height and width of the image as there are 300 of images. Unless and until that is the only option or probably i can change it programmatically.

Please help with this pathetic issue.

Thank You Pals.

enter image description here

iCodeAtApple
  • 466
  • 5
  • 16
  • 1
    In viewForAnnotation, are you setting the `centerOffset` properly? See http://stackoverflow.com/questions/13492231/change-the-images-origin-of-map-annotation-view. –  Nov 04 '13 at 15:34
  • @AnnaKarenina : The Linked helped me to Great Extent.But unfortunately i am not able to get the pins at proper lat/long. Do i need to have different centerOffset's for each pin, as i have 4 pins and whilst applying centerOffset it seems to apply only to a single pin and not for all. – iCodeAtApple Nov 06 '13 at 05:29
  • @AnnaKarenina : Finally !!! I used different offsets for each pin.Though it took me long and hard to place each pin accurately, eventually i achieved it. Since MichaelO posted the answer i would accept his. But i can't deny the fact Anna Karenina's comment helped to great extent so i upVote her answer on the link she posted. Thank You So Much Guys. !!! – iCodeAtApple Nov 06 '13 at 06:20

2 Answers2

1

You could use centerOffset to shift position according to your image sizes.

e.g. with absolute offset:

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

    static NSString* const annIdentifier = @"annotationidentifier";
    PinAnnotationView* myPinView = [[[PinAnnotationView alloc] initWithAnnotation:annotation     reuseIdentifier:annIdentifier] autorelease];

    myPinView.centerOffset = CGPointMake(0, -10.0f);

    return myPinView;
}

Replace these absolute values with calculated values according to your individual image sizes.

kalpesh
  • 1,285
  • 1
  • 17
  • 30
MichaelO
  • 56
  • 3
0

I have done something like this in a test app.

I am putting that code here you can customize it you own way, I hope this will help you.

In super view did load, i have

MapAnnotation *ann = [[MapAnnotation alloc] init];

MKCoordinateRegion region;
region.center.latitude = 31.504679;
region.center.longitude = 74.247429;
region.span.latitudeDelta = 0.01;
region.span.longitudeDelta = 0.01;

[mapView setRegion:region animated:YES];




ann.title = @"Digital Net";
ann.subtitle = @"Office";
ann.coordinate = region.center;

[mapView addAnnotation:ann];
Saad Chaudhry
  • 1,392
  • 23
  • 37