native_exif icon indicating copy to clipboard operation
native_exif copied to clipboard

GPS coords not decoded when on mobile network

Open capriele opened this issue 2 years ago • 2 comments

Good evening to everyone, I'm using the following code to get an image from a remote address but a strange behaviour happens: If the code is executed when the device is connected to a wireless network all it is working fine; otherwise if I use the normal 4g/5g network it simply doesn't work.

Could you give me some suggestion? I'm using the latest version of this plugin (native_exif: ^0.4.0).

From my side I can say that:

  • I'm able to load the image showing it on the phone screen
  • I'm using the following solution to enable "http://*" connections: link

P.S. url = "http://65.108.239.148/verdeco/allegati/commesse/4107/223005/9_4107.jpg"

import 'package:http/http.dart' as http;
import 'package:path_provider/path_provider.dart' as path_provider;
import 'package:path/path.dart' as path_instance;

Future<ExifLatLong?> getImageCoords(String url) async 
{
    // Get image from url
    final response = await http.get(Uri.parse(url));

    // Get the image name
    final imageName = path_instance.basename(url);

    // Get the document directory path
    //final appDir = await path_provider.getApplicationDocumentsDirectory();
    final appDir = await path_provider.getApplicationSupportDirectory();

    // This is the saved image path
    // You can use it to display the saved image later
    final localPath = path_instance.join(appDir.path, imageName);

    // Downloading
    final imageFile = File(localPath);
    await imageFile.writeAsBytes(response.bodyBytes);

    // Extract exif
    var exif = await Exif.fromPath(localPath);
    var coords = await exif.getLatLong();
    await exif.close();
    await imageFile.delete();
    return coords;
  }

capriele avatar Nov 11 '22 22:11 capriele