0

I'm having alot of trouble trying to identify which callout bubble has been clicked.

Is there a way of identifying the callout bubbles some how as I've tried a number of examples on here but because I'm quite new to Objective C I can't seem to work out how to use them.

The following answers I've been trying to use but I'm confused with them

How to track which annotation callout clicked

I'm looking at tagging the annotations but thats even confusing me. :(

Taken from the second answer in the above link:

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

if ([annotation isKindOfClass:[MKUserLocation class]]){
    return nil;

    if(annotation.tag == 111)
        //Do something
    else
        //Do some other thing
}

How does the first part of this snippet work, perhaps if I understood it better I'd know what I'm working with.

Also how would I go about retrieving the tags when the callout is clicked so I can make the app respond respectively.

Community
  • 1
  • 1
  • See these examples: http://stackoverflow.com/questions/4565197/how-to-find-which-annotation-send-showdetails, http://stackoverflow.com/questions/9876042/annotation-details-after-detail-disclosure-pressed, http://stackoverflow.com/questions/9462699/how-to-recognize-which-pin-was-tapped, http://stackoverflow.com/questions/9812471/mkpinannotationview-different-actions-in-different-pins, http://stackoverflow.com/questions/9797047/how-to-keep-data-associated-with-mkannotation-from-being-lost-after-a-callout-po –  Jan 09 '13 at 15:07

2 Answers2

0

You can subclass MKPinAnnotationView so you can identify it when

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKPinAnnotationView *)view

is called.

diegotrevisan
  • 499
  • 4
  • 14
0

You have to create class which extends MKAnnotation and create some property like tag and assign unique value or tag and add in mapview like.

Place* home = [[Place alloc] init] ;
home.name = [dForMap valueForKey:@"shortaddress"];
home.latitude = [[dForMap valueForKey:@"latitude"]floatValue];
home.longitude = [[dForMap valueForKey:@"longitude"]floatValue];
home.description = [dForMap valueForKey:@"shortaddress"];
home.flierid = count;
PlaceMark* from = [[PlaceMark alloc] initWithPlace:home] ;
from.flierid = count;
from.mapAnnotationType = MapAnnotationTypeProperty;    
[self addAnnotation:from];

you can check the property in didSelectAnnotationView method like this way when callout bubble is clicked.

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
PlaceMark *a = (PlaceMark*)view.annotation;
Place *test = a.place;
int tag = test.flierid;
}

Thanks.

Nagarjun
  • 6,557
  • 5
  • 33
  • 51
Banker Mittal
  • 1,918
  • 14
  • 26