Skip to content

Commit

Permalink
refs Outdooractive#59: fixups to location tracking when invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
incanus committed Aug 9, 2012
1 parent f274574 commit f781914
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions MapView/Map/RMMapView.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ - (void)correctPositionOfAllAnnotationsIncludingInvisibles:(BOOL)correctAllLayer
- (void)correctMinZoomScaleForBoundingMask;

- (void)updateHeadingForDeviceOrientation;
- (BOOL)locationCoordinateIsValid:(CLLocationCoordinate2D)coordinate;

@end

Expand Down Expand Up @@ -2581,6 +2582,9 @@ - (void)setUserTrackingMode:(RMUserTrackingMode)mode animated:(BOOL)animated
if (mode == userTrackingMode)
return;

if (mode == RMUserTrackingModeFollowWithHeading && ! [self locationCoordinateIsValid:userLocation.coordinate])
mode = RMUserTrackingModeNone;

userTrackingMode = mode;

switch (userTrackingMode)
Expand Down Expand Up @@ -2721,7 +2725,7 @@ - (void)setUserTrackingMode:(RMUserTrackingMode)mode animated:(BOOL)animated

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
if ( ! showsUserLocation || _mapScrollView.isDragging)
if ( ! showsUserLocation || _mapScrollView.isDragging || ! [self locationCoordinateIsValid:newLocation.coordinate])
return;

if ([newLocation distanceFromLocation:oldLocation])
Expand Down Expand Up @@ -2860,11 +2864,11 @@ - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLoca
if ([newLocation distanceFromLocation:oldLocation])
trackingHaloAnnotation.coordinate = newLocation.coordinate;

userLocation.layer.hidden = ((trackingHaloAnnotation.coordinate.latitude == 0 && trackingHaloAnnotation.coordinate.longitude == 0) || self.userTrackingMode == RMUserTrackingModeFollowWithHeading);
userLocation.layer.hidden = ( ! [self locationCoordinateIsValid:trackingHaloAnnotation.coordinate] || self.userTrackingMode == RMUserTrackingModeFollowWithHeading);

accuracyCircleAnnotation.layer.hidden = newLocation.horizontalAccuracy <= 10;

trackingHaloAnnotation.layer.hidden = ((trackingHaloAnnotation.coordinate.latitude == 0 && trackingHaloAnnotation.coordinate.longitude == 0) || newLocation.horizontalAccuracy > 10);
trackingHaloAnnotation.layer.hidden = ( ! [self locationCoordinateIsValid:trackingHaloAnnotation.coordinate] || newLocation.horizontalAccuracy > 10);

if ( ! [_annotations containsObject:userLocation])
[self addAnnotation:userLocation];
Expand Down Expand Up @@ -2960,6 +2964,11 @@ - (void)updateHeadingForDeviceOrientation
}
}

- (BOOL)locationCoordinateIsValid:(CLLocationCoordinate2D)coordinate
{
return (CLLocationCoordinate2DIsValid(coordinate) && ! (coordinate.latitude == 0.0 && coordinate.longitude == 0.0));
}

#pragma mark -
#pragma mark Attribution

Expand Down

0 comments on commit f781914

Please sign in to comment.