Files
MapLibreParticleLab/platform/ios/MGLUserLocation.m
Minh Nguyễn 32c7805740 Ignore invalid location updates
Avoid passing invalid locations along to the map view delegate or user location annotation.

Also, If the user wants to visit the Prime Meridian or Equator, that’s their prerogative. Mapbox GL should show them where they’re at. Null Island is a different story.

Fixes #1912.
2015-07-24 15:53:10 -07:00

75 lines
1.7 KiB
Objective-C

#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 || ! CLLocationCoordinate2DIsValid(newLocation.coordinate)) return;
if ( _location && CLLocationCoordinate2DIsValid(_location.coordinate) && [newLocation distanceFromLocation:_location] == 0) return;
if (newLocation.coordinate.latitude == 0 && newLocation.coordinate.longitude == 0) return;
[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