Challenge: Annotation Extras


#1

This seems to work OK. Feedback appreciated.

MapPoint.h

@interface MapPoint : NSObject <MKAnnotation> {
    NSString *title;
    NSString *subtitle;
    CLLocationCoordinate2D coordinate;
}

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;

- (id)initWithCoordinate:(CLLocationCoordinate2D)c title:(NSString *)t subtitle:(NSString *)st;

MapPoint.m

@synthesize coordinate, title, subtitle;

- (id)initWithCoordinate:(CLLocationCoordinate2D)c title:(NSString *)t subtitle:(NSString *)st
{
    [super init];
    coordinate = c;
    self.title = t;
    self.subtitle = st;
    return self;
}

- (void)dealloc
{
    [title release];
    [subtitle release];
    [super dealloc];
}

WhereamiMapDelegate.m

- (void)locationManager:(CLLocationManager *)manager 
   didUpdateToLocation:(CLLocation *)newLocation 
   fromLocation:(CLLocation *)oldLocation
{
    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setTimeStyle:NSDateFormatterNoStyle];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    
    NSDate *date = [newLocation timestamp];
    
    NSString *dateString = [dateFormatter stringFromDate:date];
    
    MapPoint *mp = [[MapPoint alloc]
                    initWithCoordinate:[newLocation coordinate]
                    title:[locationTitleField text]
                    subtitle:dateString];
}

#2

You fixed the problem with my code.

I didnt use setDateStyle or setTimeStyle like you did below and [color=#FF0000][dateFormatter stringFromDate:today][/color] returned blank.
[color=#FF0000][dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];[/color]

Thanks!