summaryrefslogtreecommitdiff
path: root/platform/ios/MGLUserLocation.m
blob: 054dfa686d204442adf46f50d29c23ea67966188 (plain)
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
#import "MGLUserLocation_Private.h"

@implementation MGLUserLocation
{
    CLLocationCoordinate2D _coordinate;
}

@synthesize coordinate = _coordinate;

- (instancetype)init
{
    if (self = [super init])
    {
        _coordinate = CLLocationCoordinate2DMake(MAXFLOAT, MAXFLOAT);
    }

    return self;
}

+ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key
{
    return ! [key isEqualToString:@"location"] && ! [key isEqualToString:@"heading"];
}

+ (NSSet *)keyPathsForValuesAffectingCoordinate
{
    return [NSSet setWithObject:@"location"];
}

- (void)setLocation:(CLLocation *)newLocation
{
    if ([newLocation distanceFromLocation:_location] && newLocation.coordinate.latitude != 0 &&
            newLocation.coordinate.longitude != 0)
    {
        [self willChangeValueForKey:@"location"];
        _location = newLocation;
        _coordinate = _location.coordinate;
        [self didChangeValueForKey:@"location"];
    }
}

- (void)setHeading:(CLHeading *)newHeading
{
    if (newHeading.trueHeading != _heading.trueHeading)
    {
        [self willChangeValueForKey:@"heading"];
        _heading = newHeading;
        [self didChangeValueForKey:@"heading"];
    }
}

- (NSString *)title
{
    if ( ! _title) return @"Current Location";
}

@end