我正在将 GPS 坐标写入我的 JPEG 图像,并且坐标是正确的(如我的 logcat 输出所示),但它似乎以某种方式被损坏了。读取 exif 数据会产生空值,或者在我的 GPS 的情况下:512.976698 度,512.976698 度
。谁能解释一下这个问题?
写下来:
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
。我做错了吗?
编辑:
所以,问题是我没有以正确定义的格式对其进行编码,就像您在此处看到的那样:
谁能解释一下这种格式是什么?显然第一个数字是 22/1 = 22 度,但我不知道如何计算那里的小数。
最佳答案
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 bedd/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 bedd/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
Exif 数据是标准化的,GPS 数据必须使用上述地理坐标(分、秒等)而不是分数进行编码。除非它在 exif 标签中以这种格式编码,否则它不会粘住。
如何编码:http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
如何解码:http://android-er.blogspot.com/2010/01/convert-exif-gps-info-to-degree-format.html
关于android - 如何在 Android 上的 exif 数据中保存 GPS 坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5280479/