android中的地理标记 [英] geo tagging in android

查看:32
本文介绍了android中的地理标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过代码知道android相机设置中地理标记是启用还是禁用?我们正在通过代码将地理标签附加到照片上.我们使用位置管理器,位置监听器来获取纬度和经度,并使用 Exif 接口将此坐标保存到照片中.

How to know whether the geo tagging is enabled or disabled in android camera setting through the code? We are attaching the geo tags to photos through code. We using Location Manager,Location Listener to get the latitude and longitude and save this coordinates to photo using 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 手机?

We have to add gps coordinates(latitude and longitude) to photo only when the geotag is enabled in camera setting? so how to check the status of geo tag(store location) in camera settings? I am using HTC wildfire S phone?

推荐答案

你不能以编程方式检查这个.您必须阅读所拍照片的标签并手动检查 GPS 坐标,如果标签为空,则禁用地理标记.

You can't check this programatically. You'll have to read the tags of the pictures taken and check the GPS-coordinates manually, if the tags are empty then geo-tagging is disabled.

您可以使用 ExifInterface 类从 JPEG 图像中读取 EXIF 元数据.这是解释这一点的官方文档链接:

You can use the ExifInterface class to read the EXIF metadata from JPEG images. Here's the official docs link explaining this:

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

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

Here's sample code you can use to read the tags:

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) + "

");
        builder.append("Flash: " + getExifTag(exif, ExifInterface.TAG_FLASH) + "
");
        builder.append("Focal Length: " + getExifTag(exif, ExifInterface.TAG_FOCAL_LENGTH) + "

");
        builder.append("GPS Datestamp: " + getExifTag(exif, ExifInterface.TAG_FLASH) + "
");
        builder.append("GPS Latitude: " + getExifTag(exif, ExifInterface.TAG_GPS_LATITUDE) + "
");
        builder.append("GPS Latitude Ref: " + getExifTag(exif, ExifInterface.TAG_GPS_LATITUDE_REF) + "
");
        builder.append("GPS Longitude: " + getExifTag(exif, ExifInterface.TAG_GPS_LONGITUDE) + "
");
        builder.append("GPS Longitude Ref: " + getExifTag(exif, ExifInterface.TAG_GPS_LONGITUDE_REF) + "
");
        builder.append("GPS Processing Method: " + getExifTag(exif, ExifInterface.TAG_GPS_PROCESSING_METHOD) + "
");
        builder.append("GPS Timestamp: " + getExifTag(exif, ExifInterface.TAG_GPS_TIMESTAMP) + "

");
        builder.append("Image Length: " + getExifTag(exif, ExifInterface.TAG_IMAGE_LENGTH) + "
");
        builder.append("Image Width: " + getExifTag(exif, ExifInterface.TAG_IMAGE_WIDTH) + "

");
        builder.append("Camera Make: " + getExifTag(exif, ExifInterface.TAG_MAKE) + "
");
        builder.append("Camera Model: " + getExifTag(exif, ExifInterface.TAG_MODEL) + "
");
        builder.append("Camera Orientation: " + getExifTag(exif, ExifInterface.TAG_ORIENTATION) + "
");
        builder.append("Camera White Balance: " + getExifTag(exif, ExifInterface.TAG_WHITE_BALANCE) + "
");

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

这篇关于android中的地理标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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