How to save GPS coordinates in exif data on Android?(如何在 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/3368550
、33619970/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 坐标?
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01