1

I have got an app which includes image_picker to allow the user to choose an image from their gallery or take a photo directly within the app. I need the photo to contain location data so I need the GPS GPSLatitude tag to be inside of the metadata of the image. When taking a photo just before inputting it through the gallery, the location data is saved to the metadata - whereas taking a photo in app does not contain location despite the setting save location being enabled on my devices camera settings.

Essentially, the code I am using is very simple; using the exif library to get metadata along with image_picker. Code is below:

var image = await picker.pickImage(source: ImageSource.camera);
var metadata = await readExifFromBytes(File(image.path).readAsBytesSync());
// check for gps tag
if (metadata.containsKey('GPS GPSLatitude')) {
      print("location enabled");
else{
      print("location disabled");
};

It will always print location disabled when using camera to get image, but when using gallery with a recent image - it will print location enabled The device I am using is a Xiaomi Redmi Note 8T running on android version 10.

Thomasssb1
  • 36
  • 4

1 Answers1

0

Probably your app doesn't have permission

You can Use Package permission_handler to obtain it

https://pub.dev/packages/permission_handler

This to print if the app has permission:

if (await Permission.location.isRestricted) {
      print(statuses[Permission.location]);
}
Ricky
  • 103
  • 7
  • Unfortunately, this is not the problem - I already have location permissions enabled but the location metadata just seems to be very temperamental when taking a photo using camera. – Thomasssb1 Mar 02 '23 at 23:21