可以从图像中获取图像GPS位置坐标吗?

问题描述 投票:1回答:1

我正在构建一个Flutter应用程序,用户可以在其中发布照片及其位置。使用可以从相机或图书馆获取图片。

如果用户从相机拍摄照片,我可以使用设备的GPS位置来设置照片的位置。我试图根据其元数据获取图片的GSP位置,但是,我还没有找到办法。

有可能吗?怎么最好的方法?

编辑:我在问题中加入“GPS”以表明清楚。我正试图发现拍摄照片的物理位置。我还在问题中添加了“Flutter”,以明确表示我正面临在Flutter App中解决此问题的问题。

flutter geolocation
1个回答
1
投票

如果图像是JPEG或RAW图像文件,则地理定位元数据存储为Exif标记。在Android中,这是通过ExifInterface类完成的。

标签是TAG_GPS_LATITUDETAG_GPS_LONGITUDEhttps://developer.android.com/reference/android/media/ExifInterface.html

请注意,坐标需要以合理的格式表示:度,分和秒,如dd/1,mm/1,ss/1


0
投票

我发现我之前的问题与设备的Camera权限有关。通常来自android的摄像头访问用户位置并将GPS坐标保存为Exif标签,但ios设备通常不会保存此默认设置,除非用户允许对摄像头应用程序进行位置许可。

我更改了我的应用程序以检查图像是否具有GPS坐标,并且用户决定是否要分享他的实际位置或图像位置。

我还需要做一些数学来处理坐标:

void _checkGPSData() async {
    Map<String, IfdTag> imgTags = await readExifFromBytes( File(image.path).readAsBytesSync() );

    if (imgTags.containsKey('GPS GPSLongitude')) {
      setState(() {
        _imgHasLocation = true;
        _imgLocation = exifGPSToGeoFirePoint(imgTags);
      });
    }

  }


GeoFirePoint exifGPSToGeoFirePoint(Map<String, IfdTag> tags) {

  final latitudeValue = tags['GPS GPSLatitude'].values.map<double>( (item) => (item.numerator.toDouble() / item.denominator.toDouble()) ).toList();
  final latitudeSignal = tags['GPS GPSLatitudeRef'].printable;


  final longitudeValue = tags['GPS GPSLongitude'].values.map<double>( (item) => (item.numerator.toDouble() / item.denominator.toDouble()) ).toList();
  final longitudeSignal = tags['GPS GPSLongitudeRef'].printable;

  double latitude = latitudeValue[0]
    + (latitudeValue[1] / 60)
    + (latitudeValue[2] / 3600);

  double longitude = longitudeValue[0]
    + (longitudeValue[1] / 60)
    + (longitudeValue[2] / 3600);

  if (latitudeSignal == 'S') latitude = -latitude;
  if (longitudeSignal == 'W') longitude = -longitude;

  return  GeoFirePoint(latitude, longitude);
}
© www.soinside.com 2019 - 2024. All rights reserved.