Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore 0 values of latitude and longitude on client #297

Merged
merged 6 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe obj C has this DBL_EPSILON global const that we can use, maybe we can consider its use here? I think it can be imported with float.h.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DBL_EPSILON is approximately 2.2e-16 which is too precise I think, it would give similar results to just using the != operator like we did before


@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
Loading