gpt4 book ai didi

android - android中的地理标记

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:13:06 29 4
gpt4 key购买 nike

如何通过代码知道android相机设置中的地理标记是启用还是禁用?我们通过代码将地理标签附加到照片上。我们使用 Location Manager、Location Listener 获取经纬度,并使用 Exif 接口(interface)将此坐标保存到照片中。

ExifInterface exif = new ExifInterface(/sdcard/photo/photoname.jpg);
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE,String.valueOf(latitudeValueInDecimal));
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE,String.valueOf(longitudeValueInDecimal));
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF,"N");
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF,"W");
exif.saveAttributes();

只有在相机设置中启用地理标记时,我们才必须向照片添加 gps 坐标(纬度和经度)吗?那么如何在相机设置中检查地理标签(商店位置)的状态?我在使用 HTC wildfire S 手机吗?

最佳答案

您不能以编程方式检查它。您必须读取所拍照片的标签并手动检查 GPS 坐标,如果标签为空,则地理标签将被禁用。

您可以使用 ExifInterface 类从 JPEG 图像中读取 EXIF 元数据。这是对此进行解释的官方文档链接:

http://developer.android.com/reference/android/media/ExifInterface.html

下面是您可以用来读取标签的示例代码:

Bundle bundle = getIntent().getExtras();

if (null != bundle) {
String filepath = bundle.getString(FILE_PATH_KEY);

try {
ExifInterface exif = new ExifInterface(filepath);
StringBuilder builder = new StringBuilder();

builder.append("Date & Time: " + getExifTag(exif, ExifInterface.TAG_DATETIME) + "\n\n");
builder.append("Flash: " + getExifTag(exif, ExifInterface.TAG_FLASH) + "\n");
builder.append("Focal Length: " + getExifTag(exif, ExifInterface.TAG_FOCAL_LENGTH) + "\n\n");
builder.append("GPS Datestamp: " + getExifTag(exif, ExifInterface.TAG_FLASH) + "\n");
builder.append("GPS Latitude: " + getExifTag(exif, ExifInterface.TAG_GPS_LATITUDE) + "\n");
builder.append("GPS Latitude Ref: " + getExifTag(exif, ExifInterface.TAG_GPS_LATITUDE_REF) + "\n");
builder.append("GPS Longitude: " + getExifTag(exif, ExifInterface.TAG_GPS_LONGITUDE) + "\n");
builder.append("GPS Longitude Ref: " + getExifTag(exif, ExifInterface.TAG_GPS_LONGITUDE_REF) + "\n");
builder.append("GPS Processing Method: " + getExifTag(exif, ExifInterface.TAG_GPS_PROCESSING_METHOD) + "\n");
builder.append("GPS Timestamp: " + getExifTag(exif, ExifInterface.TAG_GPS_TIMESTAMP) + "\n\n");
builder.append("Image Length: " + getExifTag(exif, ExifInterface.TAG_IMAGE_LENGTH) + "\n");
builder.append("Image Width: " + getExifTag(exif, ExifInterface.TAG_IMAGE_WIDTH) + "\n\n");
builder.append("Camera Make: " + getExifTag(exif, ExifInterface.TAG_MAKE) + "\n");
builder.append("Camera Model: " + getExifTag(exif, ExifInterface.TAG_MODEL) + "\n");
builder.append("Camera Orientation: " + getExifTag(exif, ExifInterface.TAG_ORIENTATION) + "\n");
builder.append("Camera White Balance: " + getExifTag(exif, ExifInterface.TAG_WHITE_BALANCE) + "\n");

builder = null;
} catch (IOException e) {
e.printStackTrace();
}
}

关于android - android中的地理标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12740503/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com