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
This commit is contained in:
neslihanturan 2020-12-09 20:18:10 +03:00 committed by GitHub
parent c19858069b
commit 3aa7a13ec5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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"
}
}
}