* Cleans up & documents more APIs, especially in location. * Moves `coordinate` internal and makes use of `location` to retrieve it. * Moves `title` & `subtitle` internal since part of `MGLAnnotation` protocol. * Enables `isUpdating` by privately associating weakly with a map view.
71 lines
1.5 KiB
Objective-C
71 lines
1.5 KiB
Objective-C
#import "MGLUserLocation_Private.h"
|
|
|
|
#import "MGLMapView.h"
|
|
|
|
@interface MGLUserLocation ()
|
|
|
|
@property (nonatomic, copy) NSString *title;
|
|
@property (nonatomic, copy) NSString *subtitle;
|
|
|
|
@end
|
|
|
|
@implementation MGLUserLocation
|
|
|
|
- (instancetype)init
|
|
{
|
|
if (self = [super init])
|
|
{
|
|
_location = [[CLLocation alloc] initWithLatitude:MAXFLOAT longitude: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;
|
|
[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 : @"Current Location");
|
|
}
|
|
|
|
@end
|