在jpeg中存储GPS的Android已损坏

时间:2018-08-23 12:16:10

标签: android xamarin gps exif android-gps

我创建了一个简单的Android应用程序,该应用程序可以拍照并在jpg文件的exif标签中存储设备的GPS信息。以下代码显示了此过程(我知道这很麻烦)

Android.Locations.Location loc = await client.GetLastLocationAsync();
ByteBuffer buffer = mImage.GetPlanes()[0].Buffer;
byte[] bytes = new byte[buffer.Remaining()];
buffer.Get(bytes);

using (var output = new FileOutputStream(mFile))
{
    try
    {
        output.Write(bytes);
        output.Flush();

        ExifInterface exif = new ExifInterface(mFile.AbsolutePath);
        string[] degMinSec = Location.Convert(loc.Latitude, Format.Seconds).Split(':');
        string dms = degMinSec[0] + "/1," + degMinSec[1] + "/1" + degMinSec[2] + "/1000";

        string[] degMinSec1 = Location.Convert(loc.Longitude, Format.Seconds).Split(':');
        string dms1 = degMinSec1[0] + "/1," + degMinSec1[1] + "/1" + degMinSec1[2] + "/1000";

        exif.SetAttribute(ExifInterface.TagGpsLatitude, dms);
        exif.SetAttribute(ExifInterface.TagGpsLatitudeRef, loc.Latitude < 0?"S":"N");
        exif.SetAttribute(ExifInterface.TagGpsLongitude, dms1);
        exif.SetAttribute(ExifInterface.TagGpsLongitudeRef, loc.Longitude < 0 ? "W" : "E");
        exif.SaveAttributes();

    }
    ...

现在解决问题: 当我拍照并调试 loc 变量时,它看起来像这样: enter image description here

如您所见,纬度为48.4080605,经度为15.6257273

当我调试转换后的值 dms dms1 时,它们将显示以下值:enter image description here

dms代表纬度,值48°24'29.0178'',dms1代表经度,值15°37'32.61828''。

当我在metapicz.com中查看图片exif-data时,它会显示以下值:

enter image description here

有人可以向我解释发生了什么,我做错了什么吗? 我不知道为什么它显示的位置与应该显示的位置不同

1 个答案:

答案 0 :(得分:2)

dms = degMinSec[0] + "/1," + degMinSec[1] + "/1" + degMinSec[2] + "/1000"; 

应该不是

dms = degMinSec[0] + "/1," + degMinSec[1] + "/1," + degMinSec[2] + "/1000";