Skip to content

Commit

Permalink
Ignore 0 values of latitude and longitude on client (#297)
Browse files Browse the repository at this point in the history
* limit precision when comparing coordinates

* Update CLLocation+Radar.m

* update precision to 8 decimal places

* revert version for testing

* Revert "revert version for testing"

This reverts commit 48bbd47.
  • Loading branch information
york-wei authored Jan 18, 2024
1 parent 4f51271 commit 3211df7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion RadarSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'RadarSDK'
s.version = '3.9.1'
s.version = '3.9.2'
s.summary = 'iOS SDK for Radar, the leading geofencing and location tracking platform'
s.homepage = 'https://radar.com'
s.author = { 'Radar Labs, Inc.' => '[email protected]' }
Expand Down
4 changes: 2 additions & 2 deletions RadarSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = 3.9.1;
MARKETING_VERSION = 3.9.2;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -1039,7 +1039,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = 3.9.1;
MARKETING_VERSION = 3.9.2;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
OTHER_CFLAGS = "-fembed-bitcode";
Expand Down
10 changes: 8 additions & 2 deletions RadarSDK/CLLocation+Radar.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@
@import Foundation;
#import "CLLocation+Radar.h"

const double DEGREE_EPSILON = 0.00000001;

@implementation CLLocation (Radar)

- (BOOL)isValid {
CLLocationDegrees lat = self.coordinate.latitude;
CLLocationDegrees lon = self.coordinate.longitude;

BOOL latitudeValid = lat != 0.0 && lat > -90.0 && lat < 90.0;
BOOL longitudeValid = lon != 0.0 && lon > -180.0 && lon < 180;
BOOL latitudeValid = ![self isDouble:lat withinDegreeEpsilonTo:0.0] && lat > -90.0 && lat < 90.0;
BOOL longitudeValid = ![self isDouble:lon withinDegreeEpsilonTo:0.0] && lon > -180.0 && lon < 180;
BOOL horizontalAccuracyValid = self.horizontalAccuracy > 0;

return latitudeValid && longitudeValid && horizontalAccuracyValid;
}

- (BOOL)isDouble:(double)firstValue withinDegreeEpsilonTo:(double)secondValue {
return fabs(firstValue - secondValue) < DEGREE_EPSILON;
}

@end
2 changes: 1 addition & 1 deletion RadarSDK/RadarUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ + (NSNumber *)timeZoneOffset {
}

+ (NSString *)sdkVersion {
return @"3.9.1";
return @"3.9.2";
}

+ (NSString *)deviceId {
Expand Down
6 changes: 5 additions & 1 deletion RadarSDKTests/CLLocation+RadarTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ - (void)testIsValidForLocationWithInvalidLatitudeReturnsFalse {
}

- (void)testIsValidForLocationWithLatitudeNearZeroReturnsTrue {
[self assertValidLocation:0.0001 longitude:LON horizontalAccuracy:1.0 shouldBeValid:true];
[self assertValidLocation:0.000001 longitude:LON horizontalAccuracy:1.0 shouldBeValid:true];
}

- (void)testIsValidForLocationWithLatitudeWithinFloatEpsilonOfZeroReturnsFalse {
[self assertValidLocation:0.000000009 longitude:LON horizontalAccuracy:1.0 shouldBeValid:false];
}

- (void)testIsValidForLocationWithInvalidLongitudeReturnsFalse {
Expand Down

0 comments on commit 3211df7

Please sign in to comment.