I am parsing data from a csv file with coordinates and other information. I have the pins plotted and I would like to know how to add other pieces of data in the subtitle object of the pins. Here is my approach (the object I'm trying to add is "temperature"):
ViewController.h
NSString * latitude = [infos objectAtIndex:1];
NSString * longitude = [infos objectAtIndex:2];
NSString * description =[infos objectAtIndex:3];
NSString * address = [infos objectAtIndex:4];
NSString * temperature = [infos objectAtIndex:5];
CLLocationCoordinate2D coordinate;
coordinate.latitude = latitude.doubleValue;
coordinate.longitude = longitude.doubleValue;
Location *annotation = [[Location alloc] initWithName:description address:address temperature:temperature coordinate:coordinate] ;
[mapview addAnnotation:annotation];
Location.h
@interface Location : NSObject {
NSString *_name;
NSString *_address;
NSString *_temperature;
CLLocationCoordinate2D _coordinate;
}
@property (copy) NSString *name;
@property (copy) NSString *address;
@property (copy) NSString *temperature;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
- (id)initWithName:(NSString*)name address:(NSString*)address temperature:
(NSString*)temperature coordinate:(CLLocationCoordinate2D)coordinate;
Location.m
@implementation Location
@synthesize name = _name;
@synthesize address = _address;
@synthesize coordinate = _coordinate;
@synthesize temperature = _temperature;
- (id)initWithName:(NSString*)name address:(NSString*)address temperature:(NSString*)temperature coordinate:(CLLocationCoordinate2D)coordinate {
if ((self = [super init])) {
_name = [name copy];
_address = [address copy];
_temperature = [temperature copy];
_coordinate = coordinate;
}
return self;
}
- (NSString *)title {
if ([_name isKindOfClass:[NSNull class]])
return @"Unknown charge";
else
return _name;
}
- (NSString *)subtitle {
return _address;
return _temperature;
}
As you can see I tried to add the "temperature" object in the "subtitle" method, unfortunately that didn't display in the annotation. Right now I am trying with the temperature object but I need to plot some more so I need a way to add as many objects as possible.