I'm working on a map gallery. I need location information of photos. While working on this, I encountered a wired situation. I used intent to call ACTION_OPEN_DOCUMENT and picked an image. Then used its MediaStore.Images.Media.EXTERNAL_CONTENT_URI to generate an inputstream. Finaly I passed the inputstream in to ExifInterface() and get its location. I works flawlessly.
val fileInputStream = pickedImageUri?.let { it1 -> getInputStreamFromUri(context, it1) }
Timber.e("pickedImageUri:$pickedImageUri")
Timber.e("fileInputStream:$fileInputStream")
val imageExif = fileInputStream?.let { it1 -> ExifInterface(it1) }
Timber.e("imageExif:$imageExif")
val imageLocationRaw = LatLng(
imageExif?.latLong?.get(0) ?: 0.0,
imageExif?.latLong?.get(1) ?: 0.0
)
if (imageExif != null) {
Timber.e("latlong:${imageExif.latLong}")
}
Timber.e("imageLocationRaw:$imageLocationRaw")
But I thought photo picker is more convinient for selecting photos. So I moved to photo picker. I used the same method to extract location. However, error occurs at imageExif?.latLong?. It's always null. Warning from the Logcat is 'Latitude/longitude values are not parsable. latValue=0/1,0/1,0/1, latRef=, lngValue=0/1,0/1,0/1, lngRef='
why? how can i get locaiton correctly?
I'm not the only one has encountered this problem. Here is another post about this. Retrieving GPS EXIF data from images using AndroidX ExifInterface? After reading docs carefully. I realize that this might be the way photo picker ought to works. In the docs, it says photo picker aims at providing a lite way to access meida without asking any permission which to my understanding means it won't expose any sensitive information and won't even be an option. If you need exif and a beautiful photo picker UI, you need to make your own.