2

MediaStore.Images.Media.LATITUDE and MediaStore.Images.Media.LONGITUDE was deprecated in Android Q.

Does anyway know how we can get the Media location on React Native with expo? Basically do the below without Ejecting. Android 10: fetch the gallery via MediaStore with location information

Thank you

import * as Permissions from 'expo-permissions';
import * as MediaLibrary from 'expo-media-library';
import Exif from 'react-native-exif'
...

    MediaLibrary.getAssetInfoAsync(asset).then(function (e) {
                                console.log("Location is ", e.location); //always null
                                if (e.location) {
                                    data.push(e);
                                }
                            });
    Exif.getLatLong(asset) //doesn't get location.
                          .then((loc) => { console.log('Location OK: ', loc) })
                          .catch(msg => console.log('messages: ' + msg)) 

1 Answers1

0

This may be an issue if you're using a real device and not an emulator.

When I use the iOS simulator, there are no issues getting the location with this method, if the image contains any location data.

const imageData = await MediaLibrary.getAssetInfoAsync(assetId);
console.log(imageData.location)

How ever, on my physical android device the locations field also resolves to null. Even though the image i'm testing with is the same.

But when I use expo ImagePicker, location is shown if the image contains the informations.

Also, it may be unnecessary to use react-native-exif; the method getAssetInfoAsync already returns the image EXIF data.

f.khantsis
  • 3,256
  • 5
  • 50
  • 67