0

I was wondering if it is possible to to that or if it is not what are the alternatives? I need some information that need to be shown on the map and I'm having trouble with it... MKPointAnnotation gives a good interface but I haven't been able to open more than 1 callout at once. Thanks!

P. Sami
  • 2,115
  • 2
  • 21
  • 39

2 Answers2

0

Add button in annotation and set tag for button.You can also use this with custom annotation but at the bottom line approach is same as below.You need to set identifier(tag) for open multiple annotation.

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

     {

         MKPinAnnotationView *pin = (MKPinAnnotationView *) [self.map      dequeueReusableAnnotationViewWithIdentifier: @"restMap"];
         if (pin == nil) {
            pin = [[[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"restMap"] autorelease];
          }

          else {
              pin.annotation = annotation;
               }

          // add cutom button by following way.
          UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeCustombutton];


          // you just need to find an integer value that matches your object in some way:
          // its index in your array of MKAnnotation items, or an id of some sort, etc

          NSInteger annotationValue = [self.annotations indexOfObject:annotation];

          // set the tag property of the button to the index
          detailButton.tag = annotationValue;

          pin.rightCalloutAccessoryView = detailButton;
          return pin;
    }




     -(IBAction)showDetailofannotation:(UIView*)sender {
       // get the tag value from the sender
        NSInteger annotationtag = sender.tag;
        MyAnnotationObject *selectedObject = [self.annotations objectAtIndex:annotationtag ];

   // now you know which detail view you want to show; the code that follows

        YourDetailViewController *detailView = [[YourDetailViewController alloc] initWithNibName:@"YourDetailViewController ", NSBundle:nil];
detailView.detailObject = selectedObject;

       [[self navigationController] pushViewController:detailView animated:YES];
        [detailView release];`
     }

Hope, this will help you..

Nitin
  • 7,455
  • 2
  • 32
  • 51
  • Sorry i unable add code block...Please add necessary code block. When i am able to see code bloc i will do it.. – Nitin May 06 '12 at 03:33
  • Thank you Nit, but this wasn't what I was looking for, I was trying to put images on the map on different locations and thought callouts are the solution, but i figured out from here that i need a customized annotation: http://shawnsbits.com/blog/2011/04/12/custom-map-pins-for-mapkit/ – P. Sami May 06 '12 at 13:19
  • In that case you need to use custom annotation but approach will be same. – Nitin May 06 '12 at 13:30
0

I found the solution:

You need to read this first:

http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html

and then there's an example on it here:

http://shawnsbits.com/blog/2011/04/12/custom-map-pins-for-mapkit/

The key is to load your array of annotations with the customized images in the viewDidLoad and then in mapView:viewForAnnotation: create a new MKAnnotationView and load the image into it by casting the annotation to the customized annotation that is being passed to it.

I hope this helps. Sorry if it looks kinda confusing!

P. Sami
  • 2,115
  • 2
  • 21
  • 39