gpt4 book ai didi

android - 从库中的图像访问位置数据

转载 作者:行者123 更新时间:2023-11-29 00:08:29 25 4
gpt4 key购买 nike

我有一个方法,给定一个 Uri,应该从该照片中检索位置数据。但是,我得到的只是来自 cursor.GetDouble(latitudeColumnIndex); 方法的零值

我错过了什么?

private void GetImageLocation(Uri uri)
{
string[] projection =
{
MediaStore.Images.Media.InterfaceConsts.Latitude,
MediaStore.Images.Media.InterfaceConsts.Longitude,

};

using (ICursor cursor = ContentResolver.Query(uri, projection, null, null, null))
{
if (cursor.MoveToFirst())
{
int latitudeColumnIndex = cursor.GetColumnIndex(MediaStore.Images.Media.InterfaceConsts.Latitude);
int longitudeColumnIndex = cursor.GetColumnIndex(MediaStore.Images.Media.InterfaceConsts.Longitude);

if (latitudeColumnIndex == -1 || longitudeColumnIndex == -1)
{
_newPhoto.Latitude = 0;
_newPhoto.Longitude = 0;
}

_newPhoto.Latitude = cursor.GetDouble(latitudeColumnIndex);
_newPhoto.Longitude = cursor.GetDouble(longitudeColumnIndex);
}
else
{
_newPhoto.Latitude = 0;
_newPhoto.Longitude = 0;
}

cursor.Close();
}
}

最佳答案

您应该尝试使用 ExifInterface.GetLatLong .

它接收一个 float 数组(其中将存储纬度和经度)并返回一个 bool 值,指示操作是否成功。它的用法是这样的:

var exif = new ExifInterface(uri.Path);
var latLong = new float[2];
float lat, long;

//Check if Latitude and Longitude can be retrieved
if(exif.GetLatLong(latLong))
{
lat = latLong[0];
long = latLong[1];
}
else
{
//Fallback
lat = 0;
long = 0;
}

关于android - 从库中的图像访问位置数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32052295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com