diff options
author | Justin R. Miller <incanus@codesorcery.net> | 2015-03-25 17:48:22 -0700 |
---|---|---|
committer | Justin R. Miller <incanus@codesorcery.net> | 2015-03-25 17:48:22 -0700 |
commit | f3058dbc9ad37b498fc96c748d04c678c8b16726 (patch) | |
tree | 261194afc895402b6bfe2770bd26ea63f98d5c1f /platform/ios/MGLUserLocation.m | |
parent | c7b8cb1477139da834a5ceef051d9df375bfeb03 (diff) | |
download | qtlocation-mapboxgl-f3058dbc9ad37b498fc96c748d04c678c8b16726.tar.gz |
closes #1082, refs #756: user dot on map in iOS
Diffstat (limited to 'platform/ios/MGLUserLocation.m')
-rw-r--r-- | platform/ios/MGLUserLocation.m | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/platform/ios/MGLUserLocation.m b/platform/ios/MGLUserLocation.m new file mode 100644 index 0000000000..054dfa686d --- /dev/null +++ b/platform/ios/MGLUserLocation.m @@ -0,0 +1,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 |