如何使用 Xamarin Forms 从图像属性读取地理坐标? [英] How to read Geo Coordinates From Image Property using Xamarin Forms?

查看:26
本文介绍了如何使用 Xamarin Forms 从图像属性读取地理坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张带有经纬度坐标的图像,谁能告诉我如何得到它?我试过了

I have an image with longitude and latitude coordinates, can any one tell me how do i get it? I have tried

 if (CrossMedia.Current.IsPickPhotoSupported)
           {
               MediaFile photoPicked = await CrossMedia.Current.PickPhotoAsync();
               if (photoPicked != null)
               {
                   //await DisplayAlert("Photo Location", photoPicked.Path, "OK");
                   //path = photoPicked.Path;
                   using (Stream streamPic = photoPicked.GetStream())
                   {
                       var picInfo = ExifReader.ReadJpeg(streamPic);
                       ExifOrientation orientation = picInfo.Orientation;
                       //MainImage123.Source = ImageSource.FromStream(() => photoPicked.GetStream());
                       latitude = picInfo.GpsLatitude;
                       longitude = picInfo.GpsLongitude;
                       var filepath = photoPicked.AlbumPath;
                       var filepath1 = photoPicked.Path;
                   }
               }
           }

当我选择照片并尝试获取其坐标时它会起作用,但我必须从图片库中拍摄多张照片并找到它的坐标.有谁知道如何读取图像地理坐标?请帮帮我.

It works when I picked photo and trying to get its coordinates, but I have to take multiple photos from image gallery and find its coordinates. does any one know how to read image geo coordinates? please help me.

推荐答案

您可以使用 ExifLib.PCL Nuget 包读取图像元数据,通过查看您的代码示例",我认为您正在使用 Plugin.Media 要从画廊拍摄图像/获取图像,请确保在从您的应用中拍摄照片时使用 SaveMetaData = true.将 SaveMetaData 设置为 true 后,使用 ExifLib 获取元数据,如下所示:

You can use the ExifLib.PCL Nuget Package to read an image metada, by viewing your "code sample", i think you are using the Plugin.Media to take images/get images from the galery, be sure to use SaveMetaData = true when taking an photo from your app. Once you have set the SaveMetaData to true, use the ExifLib to obtain the MetaData like this:

        MediaFile photo;

        using (Stream streamPic = photo.GetStream())
        {
            var picInfo = ExifReader.ReadJpeg(streamPic);
            double lat = picInfo.GpsLatitude;
            double lon = picInfo.GpsLongitude;
        }

此外,作为加号,您可以获得有关照片的更多信息(拍摄日期、作者、尺寸等).

Also, as a plus, you have even more info on the photo (date taken, author, size, etc.).

更新:

再次阅读后,问题似乎是您无法从图库中选择多个图像,并且不能从照片中获取纬度和经度.目前,Plugin.Media 不支持多选.

After Reading it again, it seems that the problem is that you are not able to pick multiple images from the galery, and NOT being able to get the lat and lon from the photos. At the moment, Plugin.Media doesn't support multi-picking.

这篇关于如何使用 Xamarin Forms 从图像属性读取地理坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆