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.
This commit is contained in:
Minh Nguyễn
2015-07-23 16:03:43 -07:00
parent c16b0bfb34
commit 32c7805740
2 changed files with 8 additions and 8 deletions

View File

@@ -2309,7 +2309,7 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
{
if ( ! _showsUserLocation || ! newLocation || ! CLLocationCoordinate2DIsValid(newLocation.coordinate)) return;
if ([newLocation distanceFromLocation:oldLocation] || ! oldLocation)
if (! oldLocation || ! CLLocationCoordinate2DIsValid(oldLocation.coordinate) || [newLocation distanceFromLocation:oldLocation])
{
self.userLocation.location = newLocation;

View File

@@ -37,13 +37,13 @@ NS_ASSUME_NONNULL_END
- (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