Android geotagging

How do I know if geometry snapping is enabled or disabled in the settings of the Android camera through the code? We attach geotags to photos using a code. We use the Location Manager, Location Listener, to get the latitude and longitude and save these coordinates in the photo using the 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(); 

Do we need to add gps coordinates (latitude and longitude) to the photo only when the geotag is enabled in the camera settings? so how to check the geotag status (store location) in the camera settings? Am I using an HTC Wildfire S phone?

+6
source share
1 answer

You cannot verify this programmatically. You will need to read the tags of the pictures taken and manually check the GPS coordinates, if the tags are empty, geo-tagging is disabled.

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

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

Here is an example of code that you can use to read 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) + "\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(); } } 
+1
source

Source: https://habr.com/ru/post/927001/


All Articles