From 3aa7a13ec5550d2b3240785b7bae822445dd274d Mon Sep 17 00:00:00 2001 From: neslihanturan Date: Wed, 9 Dec 2020 20:18:10 +0300 Subject: [PATCH] Make sure exif is added if exists and not addet if null or 0.0 (#4082) * Make sure exif is added if exists and not addet if null or 0.0 * Move boolean to bottom to cover both cases --- .../nrw/commons/upload/ImageCoordinates.kt | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/upload/ImageCoordinates.kt b/app/src/main/java/fr/free/nrw/commons/upload/ImageCoordinates.kt index 2beab1680..60c56f06a 100644 --- a/app/src/main/java/fr/free/nrw/commons/upload/ImageCoordinates.kt +++ b/app/src/main/java/fr/free/nrw/commons/upload/ImageCoordinates.kt @@ -34,21 +34,29 @@ class ImageCoordinates internal constructor(exif: ExifInterface?) { //If image has no EXIF data and user has enabled GPS setting, get user's location //Always return null as a temporary fix for #1599 if (exif != null) { - val latitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE) - val latitudeRef = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF) - val longitude = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE) - val longitudeRef = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF) - if (latitude != null && longitude != null && latitudeRef != null && longitudeRef != null) { + val latAndLong = exif.latLong + if (latAndLong != null) { + decLatitude = latAndLong[0] + decLongitude = latAndLong[1] + } else { + val latitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE) + val latitudeRef = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF) + val longitude = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE) + val longitudeRef = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF) + if (latitude != null && longitude != null && latitudeRef != null && longitudeRef != null) { + decLatitude = + if (ExifInterface.LATITUDE_NORTH == latitudeRef) convertToDegree(latitude) + else 0 - convertToDegree(latitude) + decLongitude = + if (ExifInterface.LONGITUDE_EAST == longitudeRef) convertToDegree(longitude) + else 0 - convertToDegree(longitude) + } + } + if (!(decLatitude == 0.0 && decLongitude == 0.0)) { + decimalCoords = "$decLatitude|$decLongitude" //If image has EXIF data, extract image coords imageCoordsExists = true Timber.d("EXIF data has location info") - decLatitude = - if (ExifInterface.LATITUDE_NORTH == latitudeRef) convertToDegree(latitude) - else 0 - convertToDegree(latitude) - decLongitude = - if (ExifInterface.LONGITUDE_EAST == longitudeRef) convertToDegree(longitude) - else 0 - convertToDegree(longitude) - decimalCoords = "$decLatitude|$decLongitude" } } }