MediaStore.Images.Media.LATITUDE和MediaStore.Images.Media.LONGITUDE在安卓Q中被弃用。
不管怎样,你知道我们如何在React Native with expo上获得媒体位置吗?基本上可以在不弹出的情况下执行下面的操作。Android 10: fetch the gallery via MediaStore with location information
谢谢
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)) 发布于 2020-03-30 16:15:31
如果您使用的是真实设备而不是仿真器,这可能是一个问题。
当我使用iOS模拟器时,如果图像包含任何位置数据,使用此方法获取位置是没有问题的。
const imageData = await MediaLibrary.getAssetInfoAsync(assetId);
console.log(imageData.location)然而,在我的物理安卓设备上,locations字段也解析为null。即使我正在测试的图像是相同的。
但是当我使用expo ImagePicker时,如果图像包含信息,就会显示位置。
而且,可能没有必要使用react-native-exif;方法getAssetInfoAsync已经返回了图像EXIF数据。
https://stackoverflow.com/questions/60285516
复制相似问题