Rodkaiser
Rodkaiser

Reputation: 61

Error writing metadata of images Flutter Native Exif

I'm using Exif Native of flutter to write geolocation of the user on the pictures taken with the app. But it always return an error:

E/MethodChannel#native_exif(32091): java.lang.NumberFormatException: Invalid GPSLongitude value given. Must be of type Double or String.
E/MethodChannel#native_exif(32091):     at com.cloudacy.native_exif.NativeExifPlugin.setAttributes(NativeExifPlugin.kt:43)
E/MethodChannel#native_exif(32091):     at com.cloudacy.native_exif.NativeExifPlugin.onMethodCall(NativeExifPlugin.kt:172)
E/MethodChannel#native_exif(32091):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/MethodChannel#native_exif(32091):     at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#native_exif(32091):     at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)

It says that the type of the value given to the function must be Double or String, but it's already a String.

It only happens with GPSLongitude and GPSLatitude (not with GPSLatitudeRef or GPSLongitudeRef). Also I can read metadata of the image, so I think its not an error opening the file.

Here is the code:

try {
        final exif = await Exif.fromPath(file.path);

        // Conversión a formato decimal
        String latitude = position.latitude.toStringAsFixed(6);
        String longitude = position.longitude.toStringAsFixed(6);

        print("Latitud EXIF: $latitude"); //printed propperly (33.408451)
        print("Longitud EXIF: $longitude"); //printd propperly (-1.579307)
        //Changed to 1.0 both for testing, same values than documentation
        latitude = '1.0';
        longitude = '1.0';

        final timedate = await exif.getOriginalDate();
        print(timedate); //printed properly

        //here crash
        await exif.writeAttribute("GPSLatitude", latitude);
        await exif.writeAttribute(
            "GPSLatitudeRef", position.latitude >= 0 ? "N" : "S");
        await exif.writeAttribute("GPSLongitude", longitude);
        await exif.writeAttribute(
            "GPSLongitudeRef", position.longitude >= 0 ? "E" : "W");

        // Verifica los valores escritos
        final lat = await exif.getAttribute("GPSLatitude");
        final latRef = await exif.getAttribute("GPSLatitudeRef");
        final long = await exif.getAttribute("GPSLongitude");
        final longRef = await exif.getAttribute("GPSLongitudeRef");

        print("EXIF Latitud: $lat $latRef");
        print("EXIF Longitud: $long $longRef");

        await exif.close();
      } catch (e) {
        print("Error al escribir o leer metadatos EXIF: $e");
      }

Result: Error al escribir o leer metadatos EXIF: PlatformException(error, Invalid GPSLongitude value given. Must be of type Double or String., null, java.lang.NumberFormatException: Invalid GPSLongitude value given. Must be of type Double or String.

But the values are correct and not null.

Upvotes: 0

Views: 23

Answers (0)

Related Questions