Skip to content

Commit

Permalink
Merge pull request #16 from OutSystems/fix/return-type-fix-limit-deci…
Browse files Browse the repository at this point in the history
…mal-digits

RMET-918 ::: Return type fix limit decimal digits
  • Loading branch information
andregrillo authored Aug 6, 2021
2 parents 2a98ae0 + 2184e2c commit 7982065
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/ios/CDVLocation.m
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,6 @@ - (void)returnLocationInfo:(NSString*)callbackId andKeepCallback:(BOOL)keepCallb
// return error
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:POSITIONUNAVAILABLE];
} else if (lData && lData.locationInfo) {
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
[formatter setMaximumFractionDigits:15];
[formatter setRoundingMode: NSNumberFormatterRoundUp];
CLLocation* lInfo = lData.locationInfo;
NSMutableDictionary* returnInfo = [NSMutableDictionary dictionaryWithCapacity:8];
NSNumber* timestamp = [NSNumber numberWithDouble:([lInfo.timestamp timeIntervalSince1970] * 1000)];
Expand All @@ -294,8 +290,16 @@ - (void)returnLocationInfo:(NSString*)callbackId andKeepCallback:(BOOL)keepCallb
[returnInfo setObject:[NSNumber numberWithDouble:lInfo.horizontalAccuracy] forKey:@"accuracy"];
[returnInfo setObject:[NSNumber numberWithDouble:lInfo.course] forKey:@"heading"];
[returnInfo setObject:[NSNumber numberWithDouble:lInfo.altitude] forKey:@"altitude"];
[returnInfo setObject:[formatter stringFromNumber:[NSNumber numberWithDouble:lInfo.coordinate.latitude]] forKey:@"latitude"];
[returnInfo setObject:[formatter stringFromNumber:[NSNumber numberWithDouble:lInfo.coordinate.longitude]] forKey:@"longitude"];

//Set maximum decimal digits to 15 for JS float compatibility
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:15];
[formatter setRoundingMode: NSNumberFormatterRoundUp];
NSString* latitude = [formatter stringFromNumber:[NSNumber numberWithDouble:lInfo.coordinate.latitude]];
NSString* longitude = [formatter stringFromNumber:[NSNumber numberWithDouble:lInfo.coordinate.longitude]];

[returnInfo setObject:[formatter numberFromString: latitude] forKey:@"latitude"];
[returnInfo setObject:[formatter numberFromString: longitude] forKey:@"longitude"];

result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:returnInfo];
[result setKeepCallbackAsBool:keepCallback];
Expand Down

0 comments on commit 7982065

Please sign in to comment.