-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWellAmI.m
61 lines (50 loc) · 1.82 KB
/
WellAmI.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// WellAmI.m
// AmIAtWherecampPDX
//
// Created by Michael Weisman on 09-09-17.
// Copyright 2009 Michael Weisman. All rights reserved.
//
#import "WellAmI.h"
#define WHERE_CAMP_LAT 45.528073
#define WHERE_CAMP_LON -122.660508
@implementation WellAmI
- (id) init
{
self = [super init];
if (self != nil) {
locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
[locationManager setDelegate:self];
}
return self;
}
-(IBAction) howAboutNow:sender{
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
[manager stopUpdatingLocation];
NSLog(@"%@",newLocation);
[self soAmI:newLocation];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
[wellAmIAtWhereCamp setStringValue:[error localizedDescription]];
}
- (void)soAmI:(CLLocation *)location {
NSDate *now = [NSDate date];
NSDate *whereCampStartTime = [NSDate dateWithNaturalLanguageString:@"October 2, 2009"];
NSDate *whereCampEndTime = [NSDate dateWithNaturalLanguageString:@"October 4, 2009"];
CLLocation *whereCampLocation = [[CLLocation alloc] initWithLatitude:WHERE_CAMP_LAT longitude:WHERE_CAMP_LON];
if ([location distanceFromLocation:whereCampLocation] <= 200) {
if ([now compare:whereCampStartTime] == NSOrderedAscending) {
[wellAmIAtWhereCamp setStringValue:@"Not Yet, but soon!"];
} else if ([now compare:whereCampEndTime] == NSOrderedDescending) {
[wellAmIAtWhereCamp setStringValue:@"No"];
} else {
[wellAmIAtWhereCamp setStringValue:@"Yes"];
}
} else {
[wellAmIAtWhereCamp setStringValue:@"No"];
}
}
@end