Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Ignore invalid location updates
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
1ec5 committed Jul 24, 2015
1 parent c16b0bf commit 32c7805
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2309,7 +2309,7 @@ - (void)locationManager:(__unused CLLocationManager *)manager didUpdateToLocatio
{
if ( ! _showsUserLocation || ! newLocation || ! CLLocationCoordinate2DIsValid(newLocation.coordinate)) return;

if ([newLocation distanceFromLocation:oldLocation] || ! oldLocation)
if (! oldLocation || ! CLLocationCoordinate2DIsValid(oldLocation.coordinate) || [newLocation distanceFromLocation:oldLocation])
{
self.userLocation.location = newLocation;

Expand Down
14 changes: 7 additions & 7 deletions platform/ios/MGLUserLocation.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ + (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key

- (void)setLocation:(CLLocation *)newLocation
{
if ([newLocation distanceFromLocation:_location] && newLocation.coordinate.latitude != 0 &&
newLocation.coordinate.longitude != 0)
{
[self willChangeValueForKey:@"location"];
_location = newLocation;
[self didChangeValueForKey:@"location"];
}
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
Expand Down

0 comments on commit 32c7805

Please sign in to comment.