【问题标题】:how to add gps data to image, flutter image_picker Android如何将gps数据添加到图像,颤动image_picker Android
【发布时间】:2020-11-15 14:05:24
【问题描述】:

flutter image_picker 图像中没有添加 gps 数据

final pickedFile = await imagePicker.getImage(source: ImageSource.camera);
final bytes = await pickedFile.readAsBytes();
final tags = await readExifFromBytes(bytes);
print("Tags : $tags ");

标签:(无 Gps 数据)

{Image ImageWidth: 4624, Image Model: Redmi Note 8 Pro, Image ImageLength: 3472, Image Orientation: Rotated 90 CW, Image DateTime: 2020:11:15 18:15:14, Image ExifOffset: 142, Image Make: Xiaomi, EXIF FNumber: 189/100, EXIF FocalLength: 543/100, EXIF ExposureTime: 50003/1000000, EXIF Flash: Flash did not fire, EXIF ISOSpeedRatings: 3750, EXIF ExifImageLength: 3472, EXIF ExifImageWidth: 4624, EXIF ApertureValue: 46/25, EXIF ShutterSpeedValue: -431/100, EXIF SubSecTime: 530}

顺便说一句,拍照时(第一次)没有要求我允许位置,我需要添加任何权限吗?

【问题讨论】:

  • 这是什么意思,你需要一个图片的位置。或点击图片时的唯一位置
  • 需要照片的位置,默认相机应用拍摄的照片会添加位置数据到图像中。
  • @invariant,你能完成你的问题吗?你能发布你的解决方案吗?

标签: android flutter dart


【解决方案1】:
  1. 如果您需要图像位置图库和相机, 请参阅此链接。

Is possible to get Image GPS location coordinates from the Image?

或者 如果这适合您,我也有一个客户选项。

  1. 如果只需要在您的应用打开的相机图片图像时的位置,

使用简单的方法

File _image; 
final picker = ImagePicker();

 Future getImage() async { 
final pickedFile = await picker.getImage(source: ImageSource.camera);

 setState(() {
 if (pickedFile != null) {

// your will take user location  at this time
 _image = File(pickedFile.path); 
    }
 else { 
    print('No image selected.');
    }
 }); 

【讨论】:

  • 感谢您的回复,可能是我的问题不清楚。使用图像选择器拍摄的照片没有将 gps 数据添加到图像中,请参阅上面的标签输出。通常当我们拍摄照片时,会显示一个对话框“你想允许定位吗”,这在我的手机上没有发生,但我在模拟器中运行时弹出了这个对话框。
【解决方案2】:

这是我们用来添加 GPS 信息的:

      final picker = ImagePicker();

      picker.getImage(source: ImageSource.camera).then((pickedFile) async {
        var myImagePath = coreNotifier.myCurrentPath.absolute.path;

        final exif =
            dd.FlutterExif.fromBytes(await pickedFile!.readAsBytes());

        Position position = await _determinePosition();

        await exif.setLatLong(position.latitude, position.longitude);
        await exif.saveAttributes();

        final modifiedImage = await exif.imageData;
        var imageName = "imgName..";
        File imageFile = new File("$myImagePath/$imageName.jpg");
        imageFile.writeAsBytes(
          List.from(modifiedImage!),
        );
        coreNotifier.reload();
      });

也使用这个包:

import 'package:geolocator/geolocator.dart';
import 'package:flutter_exif_plugin/flutter_exif_plugin.dart' as dd;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-29
    • 1970-01-01
    • 2020-10-15
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    • 1970-01-01
    • 2020-12-24
    相关资源
    最近更新 更多