google / cameraview

[DEPRECATED] Easily integrate Camera features into your Android app
Apache License 2.0
4.74k stars 1.03k forks source link

Geolocation Exif #255

Open leonardonogueira opened 5 years ago

leonardonogueira commented 5 years ago

Hi Everyone. Is there a way to set Geolocation Exif data (ExifInterface.TAG_GPS_*) on preview time? I could make this work on onPictureTaken, before generating the picture bitmap from the byte array, but I'd like to know if there's a better way to do this. Let's assume the user has already allowed all the required permissions. I saw there's a way to set the Geolocation on Camera parameters (mCamera.getParameters().setGpsLatitude), but as the camera object is private, i don't know how to to this. Thanks a lot.

The working code i used in my case is the following:

try {
                ExifInterface exif = new ExifInterface(file.getAbsolutePath());

                exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, "******");
                exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, "*");
                exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, "******");
                exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, "*");

                exif.saveAttributes();
            } catch (IOException e) {
                e.printStackTrace();
            }