Skip to content

Commit

Permalink
set speed and heading to nil instead of -1 mauron85#15
Browse files Browse the repository at this point in the history
  • Loading branch information
CoooWeee committed Nov 6, 2021
1 parent 11e9ada commit bb747f9
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions BackgroundGeolocation/MAURLocation.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
MAX_SECONDS_FROM_NOW = 86400
};

// some CLLocation properties use -1 to indicate they are not defined
NSNumber * parseDouble(double value, bool nullifyNegativeOne) {
if (nullifyNegativeOne && value == -1) {
return nil;
}

return [NSNumber numberWithDouble:value];
}

@interface MAURLocationMapper : NSObject
- (NSDictionary*) withDictionary:(NSDictionary*)values;
- (NSArray*) withArray:(NSArray*)values;
Expand Down Expand Up @@ -77,13 +86,13 @@ + (instancetype) fromCLLocation:(CLLocation*)location;
MAURLocation *instance = [[MAURLocation alloc] init];

instance.time = location.timestamp;
instance.accuracy = [NSNumber numberWithDouble:location.horizontalAccuracy];
instance.altitudeAccuracy = [NSNumber numberWithDouble:location.verticalAccuracy];
instance.speed = [NSNumber numberWithDouble:location.speed];
instance.heading = [NSNumber numberWithDouble:location.course]; // will be deprecated
instance.altitude = [NSNumber numberWithDouble:location.altitude];
instance.latitude = [NSNumber numberWithDouble:location.coordinate.latitude];
instance.longitude = [NSNumber numberWithDouble:location.coordinate.longitude];
instance.accuracy = parseDouble(location.horizontalAccuracy, false);
instance.altitudeAccuracy = parseDouble(location.verticalAccuracy, false);
instance.speed = parseDouble(location.speed, true);
instance.heading = parseDouble(location.course, true); // will be deprecated
instance.altitude = parseDouble(location.altitude, false);
instance.latitude = parseDouble(location.coordinate.latitude, false);
instance.longitude = parseDouble(location.coordinate.longitude, false);

return instance;
}
Expand All @@ -99,14 +108,14 @@ + (NSDictionary*) toDictionary:(CLLocation*)location;

NSNumber* timestamp = [NSNumber numberWithDouble:([location.timestamp timeIntervalSince1970] * 1000)];
[dict setObject:timestamp forKey:@"time"];
[dict setObject:[NSNumber numberWithDouble:location.horizontalAccuracy] forKey:@"accuracy"];
[dict setObject:[NSNumber numberWithDouble:location.verticalAccuracy] forKey:@"altitudeAccuracy"];
[dict setObject:[NSNumber numberWithDouble:location.speed] forKey:@"speed"];
[dict setObject:[NSNumber numberWithDouble:location.course] forKey:@"heading"];
[dict setObject:[NSNumber numberWithDouble:location.course] forKey:@"bearing"];
[dict setObject:[NSNumber numberWithDouble:location.altitude] forKey:@"altitude"];
[dict setObject:[NSNumber numberWithDouble:location.coordinate.latitude] forKey:@"latitude"];
[dict setObject:[NSNumber numberWithDouble:location.coordinate.longitude] forKey:@"longitude"];
[dict setObject:parseDouble(location.horizontalAccuracy, false) forKey:@"accuracy"];
[dict setObject:parseDouble(location.verticalAccuracy, false) forKey:@"altitudeAccuracy"];
[dict setObject:parseDouble(location.speed, true) forKey:@"speed"];
[dict setObject:parseDouble(location.course, true) forKey:@"heading"];
[dict setObject:parseDouble(location.course, true) forKey:@"bearing"];
[dict setObject:parseDouble(location.altitude, false) forKey:@"altitude"];
[dict setObject:parseDouble(location.coordinate.latitude, false) forKey:@"latitude"];
[dict setObject:parseDouble(location.coordinate.longitude, false) forKey:@"longitude"];

return dict;
}
Expand Down Expand Up @@ -346,4 +355,4 @@ -(id) copyWithZone: (NSZone *) zone
return copy;
}

@end
@end

0 comments on commit bb747f9

Please sign in to comment.