diff --git a/lib/models/location/location.dart b/lib/models/location/location.dart index 35ace4379..2ef539e5f 100644 --- a/lib/models/location/location.dart +++ b/lib/models/location/location.dart @@ -12,4 +12,18 @@ class Location with _$Location { factory Location.fromJson(Map 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; + } } diff --git a/lib/services/local_file_update_service.dart b/lib/services/local_file_update_service.dart index 7cdec9c4a..663fec160 100644 --- a/lib/services/local_file_update_service.dart +++ b/lib/services/local_file_update_service.dart @@ -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!,