如何在 Android 上的 exif 数据中保存 GPS 坐标?

How to save GPS coordinates in exif data on Android?(如何在 Android 上的 exif 数据中保存 GPS 坐标?)

本文介绍了如何在 Android 上的 exif 数据中保存 GPS 坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 GPS 坐标写入我的 JPEG 图像,并且坐标是正确的(如我的 logcat 输出所示),但它似乎以某种方式被损坏了.读取 exif 数据会产生空值,或者在我的 GPS 的情况下:512.976698 度,512.976698 度.谁能解释一下这个问题?

I am writing GPS coordinates to my JPEG image, and the coordinates are correct (as demonstrated by my logcat output) but it appears that it's being corrupted somehow. Reading the exif data results in either null values or, in the case of my GPS: 512.976698 degrees, 512.976698 degrees. Can anyone shed some light on this problem?

写下来:

        try {
            ExifInterface exif = new ExifInterface(filename);
            exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, latitude);
            exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, longitude);
            exif.saveAttributes();
            Log.e("LATITUDE: ", latitude);
            Log.e("LONGITUDE: ", longitude);


        } catch (IOException e) {
            e.printStackTrace();
        }

并阅读它:

        try {
            ExifInterface exif = new ExifInterface("/sdcard/globetrotter/mytags/"+ TAGS[position]);
            Log.e("LATITUDE EXTRACTED", exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE));
            Log.e("LONGITUDE EXTRACTED", exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE));
        } catch (IOException e) {
            e.printStackTrace();
        }

它进入(例如)37.715183-117.260489和出来33619970/65540、14811136/336855033619970/65540、14811136/3368550.我做错了吗?

It goes in (for example) 37.715183, -117.260489 and comes out 33619970/65540, 14811136/3368550, 33619970/65540, 14811136/3368550. Am I doing it wrong?

所以,问题是我没有以正确定义的格式对其进行编码,就像您在此处看到的那样:

So, the problem is I am not encoding it in the properly defined format, which is something like you see here:

谁能解释一下这种格式是什么?显然第一个数字是 22/1 = 22 度,但我不知道如何计算那里的小数.

Can anyone explain what this format is? Obviously the first number is 22/1 = 22 degrees, but I can't figure out how to compute the decimal there.

推荐答案

GPS纬度

表示纬度.纬度表示为三给出度数的 RATIONAL 值,分,秒,分别.如果纬度用度数表示,分和秒,一种典型的格式将是 dd/1,mm/1,ss/1.当度和分钟用于例如,分钟的分数是保留小数点后两位,格式为 dd/1,mmmm/100,0/1.

Indicates the latitude. The latitude is expressed as three RATIONAL values giving the degrees, minutes, and seconds, respectively. If latitude is expressed as degrees, minutes and seconds, a typical format would be dd/1,mm/1,ss/1. When degrees and minutes are used and, for example, fractions of minutes are given up to two decimal places, the format would be dd/1,mmmm/100,0/1.

https://docs.google.com/viewer?url=http%3A%2F%2Fwww.exif.org%2FExif2-2.PDF

Android 文档对此没有任何解释:http://developer.android.com/reference/android/media/ExifInterface.html#TAG_GPS_LATITUDE

The Android docs specify this without explanation: http://developer.android.com/reference/android/media/ExifInterface.html#TAG_GPS_LATITUDE

Exif 数据是标准化的,GPS 数据必须使用上述地理坐标(分、秒等)而不是分数进行编码.除非它在 ​​exif 标签中以这种格式编码,否则它不会粘住.

Exif data is standardized, and GPS data must be encoded using geographical coordinates (minutes, seconds, etc) described above instead of a fraction. Unless it's encoded in that format in the exif tag, it won't stick.

如何编码:http://en.wikipedia.org/wiki/Geographic_coordinate_conversion

如何解码:http://android-er.blogspot.com/2010/01/convert-exif-gps-info-to-degree-format.html

这篇关于如何在 Android 上的 exif 数据中保存 GPS 坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 Android 上的 exif 数据中保存 GPS 坐标?

基础教程推荐