Custom data variables in mkannotation

I have a map display controller (UIViewController, MKMapView) with its delegate (HCIResultMapViewController).

I want to have the following functionality in this part.

1). I want to use my own NSObject so that I can link other details along with basic objects like title, subtitles, etc.

Therefore, according to my needs, I am encoded as follows

In HCIResultMapViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

_houseList = [[_resultList objectForKey:@"result"] objectForKey:@"listings"];

// NSLog([_houseList description]);

int i = 0;

for (NSDictionary *house in _houseList) {

    HCIAnnotationViewController *annotation = [[HCIAnnotationViewController alloc]
                                     initwithHouse:house];
    [_mapView addAnnotation:annotation];
    // NSLog(@"asdjhasdjsajdhaksdjghasdasdjahsdahskvdka");
    self.currIdentifier = i;
    i++;
}

[_mapView setShowsUserLocation:NO];
}

Other delegate features

-(void) mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {

for (NSObject<MKAnnotation> *annotation in _mapView.selectedAnnotations) {
    NSLog(@"hellomaster");
    NSLog(annotation.title);
    if ([annotation isKindOfClass:[HCIAnnotationViewController class]]) {
        NSLog(@"hellomaster");
    }
}

Last

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

NSString *identifier = @"currIdentifier";

    MKPinAnnotationView *annotationView =
    (MKPinAnnotationView *)[_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

    if (annotationView == nil) {
        annotationView = [[MKPinAnnotationView alloc]
                          initWithAnnotation:annotation
                          reuseIdentifier:identifier];
    } else {
        annotationView.annotation = annotation;
    }

    annotationView.enabled = YES;
    annotationView.canShowCallout = YES;
annotationView.tag = self.currIdentifier;

    // Create a UIButton object to add on the
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton setTitle:annotation.title forState:UIControlStateNormal];
    [annotationView setRightCalloutAccessoryView:rightButton];

/*
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
    [leftButton setTitle:annotation.title forState:UIControlStateNormal];
    [annotationView setLeftCalloutAccessoryView:leftButton];
  */  
    return annotationView;
}

But I see that class equivalence fails. Can you tell me what I am doing wrong?

I think I want, in simple words, how can I send some data (NSDictionary *) along with the annotation so that I can receive it when I want?

, . , Google .., .

+5
2

, . , . , .

, , . , , , , viewforannotation. , , . , , .

- , , .

+1

NSMutableDictionary instand NSString.
AnnotationView:

#import <MapKit/MapKit.h>

@interface AnnotationView : MKPlacemark

@property (nonatomic, readwrite, assign) CLLocationCoordinate2D coordinate;

@property (nonatomic, strong) NSString *title; //Here You cam set `NSMutableDictionary` instand of `NSString`
@property (nonatomic, strong) NSString *subtitle; //Here You cam set `NSMutableDictionary` instand of `NSString`


@end

.m file

#import "AnnotationView.h"

@implementation AnnotationView

- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate addressDictionary:(NSDictionary *)addressDictionary
{
    if ((self = [super initWithCoordinate:coordinate addressDictionary:addressDictionary]))
    {
        self.coordinate = coordinate;
    }
    return self;
}

@end

// #import "AnnotationView.h" .m file:

CLLocationCoordinate2D pCoordinate ;
pCoordinate.latitude = LatValue;
pCoordinate.longitude = LanValue;

// Create Obj Of  AnnotationView class  

AnnotationView *annotation = [[AnnotationView alloc] initWithCoordinate:pCoordinate addressDictionary:nil] ;

    annotation.title = @"I m Here";
    annotation.subtitle = @"This is Sub Tiitle";

[self.mapView addAnnotation:annotation];
+1

All Articles