Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@capacitor/camera 6.0.1 pickImages results has zeros/empty in exif GPS data on Android #2147

Open
danbritt opened this issue Jul 8, 2024 · 8 comments

Comments

@danbritt
Copy link

danbritt commented Jul 8, 2024

Bug Report

Plugin(s)

@capacitor/camera 6.0.1

Capacitor Version

   Capacitor Doctor

Latest Dependencies:

  @capacitor/cli: 6.1.0
  @capacitor/core: 6.1.0
  @capacitor/android: 6.1.0
  @capacitor/ios: 6.1.0

Installed Dependencies:

  @capacitor/ios: not installed
  @capacitor/cli: 6.1.0
  @capacitor/android: 6.1.0
  @capacitor/core: 6.1.0

[success] Android looking great! 👌

Platform(s)

Android. Tested on physical device with Android 12 and 14

Current Behavior

When you select a photo that has a location, the exif data returned has zeros/blanks in all the GPS properties. So it appears the GPS data is actually missing for some reason. Example:

{
  ...
  "GPSAltitude": "0/1",
  "GPSAltitudeRef": "0",
  "GPSDateStamp": "",
  "GPSImgDirection": "0/1",
  "GPSImgDirectionRef": "",
  "GPSLatitude": "0/1,0/1,0/1",
  "GPSLatitudeRef": "",
  "GPSLongitude": "0/1,0/1,0/1",
  "GPSLongitudeRef": "",
  "GPSTimeStamp": "00:00:00",
  "GPSVersionID": "\u0000\u0000\u0000\u0000",
  ...
}

Expected Behavior

I would expect the GPS information to have the proper values.

Code Reproduction

Minimal example app: https://github.com/danbritt/capacitor-photo-picker-example

Other Technical Details

Additional Context

I've also attempted to retrieve the file from the path returned using the Filesystem plugin, and then read the exif using a different npm package. I got the same result with the missing/zero'd out GPS properties.

@ryaa
Copy link

ryaa commented Jul 17, 2024

@danbritt
In Android with SDK >=29, you need ACCESS_MEDIA_LOCATION permission.
Make sure to request for permission before pick image and then GPS should return correctly. Or you can always add it yourself using this plugin https://github.com/capacitor-community/exif

@danbritt
Copy link
Author

I found an older issue about this problem where someone recommended doing that and it did not work for me. If you can make the example work by doing that, please fork the repo and post a link to the working one.

Thank you for the link to that plugin. I will give it a try to fix the issue. However, I still feel that the Camera plugin should provide this functionality since it does return the exif data as one of the properties in the result.

@danbritt
Copy link
Author

I had some time today to try to implement that plugin on the project I'm working on. I do have that permission in my AndroidManifest.xml, but getCoordinates() is returning undefined instead of the lat/lon values.

I appreciate the attempt to solve the issue!

What's odd is that this only applies when picking photos from the photo album. If I use the camera plugin to capture a photo, the GPS info is present in the exif data. Same if I choose a non-album image (using the FilePicker plugin from https://github.com/capawesome-team/capacitor-plugins)

@ryaa
Copy link

ryaa commented Jul 18, 2024

@danbritt I confirm the problem with the camera plugin getPhoto method not including GPS coordinates in the returned EXIF metadata. I tested this on my Android and even though the photo has the coordinates and the Android manifest includes <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" /> permission, the returned result don't have the coordinates. I will try to research this more and will follow up with my findings...

@danbritt
Copy link
Author

That is very interesting. For me, getPhoto returns the GPS data in the exif, but pickImages does not.

@ryaa
Copy link

ryaa commented Jul 29, 2024

@danbritt it seems that the problem is because the new photo picker (which is used in Capacitor Camera v6 - see https://capacitorjs.com/docs/updating/6-0#camera) redacts GSP data from EXIF, even when ACCESS_MEDIA_LOCATION permission is present. More details can be found here https://issuetracker.google.com/issues/243294058?pli=1

I am not sure how that can be fixed, unless Capacitor Camera switch to use some alternative instead of the google photo picker API.

NOTE: this file picker seems to return GPS data in EXIF (see https://capawesome.io/plugins/file-picker/) as it uses Intent.ACTION_PICK approach.

@danbritt
Copy link
Author

@ryaa

Thanks for the research and information you presented. I will try swapping to the capawesome plugin.

@danbritt
Copy link
Author

@ryaa I swapped to using the capawesome plugin and it works great. Thanks again for the suggestion and the research on the underlying issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants