如何保存在EXIF数据在Android上的GPS坐标? [英] How to save GPS coordinates in exif data on Android?

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

问题描述

我写的GPS坐标,以我的JPEG图像,坐标是正确的(就证明了我的logcat输出),但现在看来,它的被损坏不知何故。阅读在任一空值的EXIF数据结果,或在我的GPS的情况下: 512.976698度,512.976698度。任何人都可以提供一些线索对这个问题?

写它:

 尝试{
            ExifInterface EXIF​​ =新ExifInterface(文件名);
            exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE,纬度);
            exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE,经度);
            exif.saveAttributes();
            Log.e(纵横,纬度);
            Log.e(经度,经度);


        }赶上(IOException异常E){
            e.printStackTrace();
        }
 

和阅读它:

 尝试{
            ExifInterface EXIF​​ =新ExifInterface(/ SD卡/周游世界/ mytags /+ TAGS [位置]);
            Log.e(纵横提取的,exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE));
            Log.e(经度提取的,exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE));
        }赶上(IOException异常E){
            e.printStackTrace();
        }
 

它去的(例如) 37.715183 -117.260489 键,出来 33619970 / 65540,三百三十六万八千五百五十零分之一千四百八十一万一千一百三十六六万五千五百四十〇分之三千三百六十一万九千九百七十零,三百三十六万八千五百五十○分之一千四百八十一万一千一百三十六。我是不是做错了?

编辑:

所以,问题是,我没有在正确定义的格式,这是一样的东西,你在这里看到其编码:

谁能解释这是什么格式?显然,第一个数字是22/1 = 22度,但我想不出如何计算小数点那里。

解决方案
  

GPSLatitude

     

表示纬度。纬度EX pressed三   有理值赋予度,   分钟和秒。   如果纬度pssed为度EX $ P $,   分和秒,典型的格式   将 DD / 1毫米/ 1,SS / 1 。当度   和分钟的使用和,对于   例如,分钟的级分是   放弃了到小数点后两位,在   格式将是 DD / 1,MMMM / 100,0 / 1

     

<一个href="https://docs.google.com/viewer?url=http%3A%2F%2Fwww.exif.org%2FExif2-2.PDF">https://docs.google.com/viewer?url=http%3A%2F%2Fwww.exif.org%2FExif2-2.PDF

Android的文档指定这个不用解释:<一href="http://developer.android.com/reference/android/media/ExifInterface.html#TAG_GPS_LATITUDE">http://developer.android.com/reference/android/media/ExifInterface.html#TAG_GPS_LATITUDE

的Exif数据是标准化的,与GPS数据必须连接使用的地理坐标(分,秒等)之上,而不是一小部分描述$ C $光盘。除非它是连接codeD在EXIF标签的格式,也不会粘。

如何连接code:<一href="http://en.wikipedia.org/wiki/Geographic_coordinate_conversion">http://en.wikipedia.org/wiki/Geographic_coordinate_conversion

如何去code:<一href="http://android-er.blogspot.com/2010/01/convert-exif-gps-info-to-degree-format.html">http://android-er.blogspot.com/2010/01/convert-exif-gps-info-to-degree-format.html

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?

writing it:

        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();
        }

and reading it:

        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();
        }

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?

EDIT:

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

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.

解决方案

GPSLatitude

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

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

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.

How to encode: http://en.wikipedia.org/wiki/Geographic_coordinate_conversion

How to decode: http://android-er.blogspot.com/2010/01/convert-exif-gps-info-to-degree-format.html

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆