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

Some photos have gps, some photos don't. #177

Closed
hungdev opened this issue Feb 9, 2022 · 10 comments
Closed

Some photos have gps, some photos don't. #177

hungdev opened this issue Feb 9, 2022 · 10 comments

Comments

@hungdev
Copy link

hungdev commented Feb 9, 2022

they were all taken from the same camera

one photo
image

another photo
image

what's wrong with me?

here is my code:

      const tags = await ExifReader.load(arrbf, { expanded: true });
      console.tron.log('tags', tags)
@hungdev hungdev changed the title [React native] Simulator can get GPS lat long, but real device is not. Some photos have gps, some photos don't. Feb 9, 2022
@mattiasw
Copy link
Owner

mattiasw commented Feb 9, 2022

Hi! That's unfortunately how it is. Not all photos get a location recorded. My experience is that it's actually quite common that photos are missing GPS values. If you don't think this is the reason and you have a photo that has GPS in another Exif parser but not in ExifReader, please provide an example file and I'll have a look. Exiftool is a good program to check in. Here is an online version: http://exif.regex.info/exif.cgi

@hungdev
Copy link
Author

hungdev commented Feb 9, 2022

@mattiasw i try it on http://exif.regex.info/exif.cgi and even on your website https://mattiasw.github.io/ExifReader/amd/
it can still give data about gps. But in my code it only returns the data like this. It doesnt include gps information.
image
and with expaned: true param
image

@mattiasw
Copy link
Owner

mattiasw commented Feb 9, 2022

That is weird. 🤔 Could it have something to do with React Native again? That the phone removes the location before using the photo or something. I've read that e.g. Iphone does that when uploading to a web site but not sure if it's the same in React Native.

https://apple.stackexchange.com/questions/326789/gps-exif-from-iphone-photo-upload-in-safari

@tomgreco
Copy link

tomgreco commented Mar 6, 2022

When selecting images from the photo gallery on iOS I am able to get the EXIF data if I use another library that has native functionality.
https://github.com/ivpusic/react-native-image-crop-picker/blob/356985acaaae425acf1ea7ad06910158420d907f/ios/src/ImageCropPicker.m

Search "includeExif" and you can see where it gets the exif data from the selected images.

However, with ExifReader I am not able to get the same EXIF data.
I don't have a possible solution in mind but figured I'd leave you with the information in case you wanted to dig into it :)

@tomgreco
Copy link

tomgreco commented Mar 6, 2022

base64ImageIos.txt
Attached is the base64 data for the image I used in my screenshots below if you want to test against it.

When using the react-native-image-crop-picker here is what the EXIF data returned looks like. Notice it has lat/long/altitude
image

When using this library I do not get any of that information in the exif response.
image


EDIT: I don't think the issue has anything to do with your library, I believe there is some gypsy magic happening to obtain the EXIF data natively and it's not copying that to the output file.
ivpusic/react-native-image-crop-picker#1736

@mattiasw
Copy link
Owner

mattiasw commented Mar 6, 2022

When searching the web regarding this I saw a lot of people having trouble getting the location data using regular Exif libraries and React Native. I think you're on to something here @tomgreco, you may have to use a native implementation to be able to read the location data from a photo. That's a bit sad if it's true but not much we can do about it I guess. Would be nice to know for sure though.

@kyoz
Copy link

kyoz commented Jul 1, 2022

This issue is really a pain. Yes as @mattiasw say, using native solution it'll work, but there is some information I think it'll help (spend my whole day to found it 😢 ).

Using native solution with work on iOS and Android which have targetSDKVersion < 29

In Android with SDK >= 29, you need this permission:

 <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />

Don't forget to request for this permission before you try to pick and read EXIF.

That's it, but...It's somehow funny that, on some device with different build of Android (Nokia, Samsung, Pixel...). Even with sdk > 29, you still can read EXIF easily without ACCESS_MEDIA_LOCATION. That's really a mess to support all version of Android. But to be sure, I think the solution i'v point out above is enough.

Hope it help. Read more here

@mattiasw
Copy link
Owner

mattiasw commented Jul 1, 2022

Thank you for your research into this @kyoz! I know other developers will appreciate the time you put into this.

@kyoz
Copy link

kyoz commented Jul 1, 2022

Thanks @mattiasw for great plugin. One more thing I just found out is that, also this permission is sensitive, but if you already granted permission for these (which we usually use to read and write image, mean scoped storage):

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

It will grant you ACCESS_MEDIA_LOCATION permission right away without any prompt 😆

@mattiasw
Copy link
Owner

mattiasw commented Aug 6, 2022

I'm closing this since it seems there's not much to do for this library. But please keep commenting if anything new comes up. This discussion is linked from the README so people can find it.

@mattiasw mattiasw closed this as completed Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants