blob: 0b0cf70cbe69c6ed7110d55d19dec9e67ef952b5 (
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#import "MGLUserLocation_Private.h"
#import "MGLMapView.h"
NS_ASSUME_NONNULL_BEGIN
@interface MGLUserLocation ()
@property (nonatomic, weak) MGLMapView *mapView;
@end
NS_ASSUME_NONNULL_END
@implementation MGLUserLocation
- (instancetype)initWithMapView:(MGLMapView *)mapView
{
if (self = [super init])
{
_location = [[CLLocation alloc] initWithLatitude:MAXFLOAT longitude:MAXFLOAT];
_mapView = mapView;
}
return self;
}
+ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key
{
return ! [key isEqualToString:@"location"] && ! [key isEqualToString:@"heading"];
}
+ (NS_SET_OF(NSString *) *)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;
[self didChangeValueForKey:@"location"];
}
}
- (BOOL)isUpdating
{
return self.mapView.userTrackingMode != MGLUserTrackingModeNone;
}
- (void)setHeading:(CLHeading *)newHeading
{
if (newHeading.trueHeading != _heading.trueHeading)
{
[self willChangeValueForKey:@"heading"];
_heading = newHeading;
[self didChangeValueForKey:@"heading"];
}
}
- (CLLocationCoordinate2D)coordinate
{
return self.location.coordinate;
}
- (NSString *)title
{
return (_title ? _title : @"You Are Here");
}
@end
|