Handle infinite or Nan values

This commit is contained in:
Neeraj Gupta 2023-05-02 17:43:21 +05:30
parent 12edb7a740
commit c20cb8040a
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1
2 changed files with 15 additions and 3 deletions

View file

@ -12,4 +12,18 @@ class Location with _$Location {
factory Location.fromJson(Map<String, Object?> json) =>
_$LocationFromJson(json);
static isValidLocation(Location? location) {
if (location == null) return false;
if (location.latitude == null || location.longitude == null) return false;
final latValue = location.latitude!;
final longValue = location.longitude!;
if (latValue.isNaN || latValue.isNaN || latValue == 0.0) {
return false;
}
if (longValue.isInfinite || longValue.isInfinite || longValue == 0.0) {
return false;
}
return true;
}
}

View file

@ -257,9 +257,7 @@ class LocalFileUpdateService {
for (ente.File file in enteFiles) {
final Location? location = await tryLocationFromExif(file);
if (location != null &&
(location.latitude ?? 0) != 0.0 &&
(location.longitude ?? 0) != 0.0) {
if (location != null && Location.isValidLocation(location)) {
remoteFilesToUpdate.add(file);
fileIDToUpdateMetadata[file.uploadedFileID!] = {
pubMagicKeyLat: location.latitude!,