【发布时间】:2016-06-07 19:12:40
【问题描述】:
我在 Xamarin 中使用 MediaPicker 拍照。我启动地理定位服务,然后在拍摄照片后,我将图像的字节数组和位置信息发送到我自己的平台特定实现,以在图像的元数据中添加位置信息。
然后我将图像保存为文件,然后通过电子邮件将其发送给自己,以便我可以在外部应用程序 (Picasa) 中打开它,以确保 GPS 信息已正确存储。
我遇到的问题是纬度和高度显示正常,但经度始终为零。我在我的应用程序中设置了断点,并验证元数据设置正确并且所有信息都具有有效值。我不知道这里发生了什么。
以下一些代码可能是多余的或效率低下的,因为我一直在测试添加元数据的不同方法。我在此元数据添加方法的 iOS 实现中的应用程序中使用以下代码:
public byte[] AddPositionInformation(byte[] bytes, SaleScribe.PCL.Services.Geolocation.Position position)
{
var data = NSData.FromArray(bytes);
UIKit.UIImage original = UIKit.UIImage.LoadFromData(data);
CGImageSource myImageSource = CGImageSource.FromData(original.AsJPEG());
var options = new CGImageDestinationOptions();
options.GpsDictionary = new CoreGraphics.CGImagePropertiesGps();
options.GpsDictionary.Latitude = (float)position.Latitude;
options.GpsDictionary.Longitude = (float)position.Longitude;
options.GpsDictionary.Altitude = (int)position.Altitude;
NSMutableData mutableData = new NSMutableData();
using(var dest = CGImageDestination.Create(mutableData, myImageSource.TypeIdentifier, 1, new CGImageDestinationOptions()))
{
dest.AddImage(myImageSource, (int)(myImageSource.ImageCount - 1), options);
dest.Close();
}
return (mutableData as NSData).ToArray();
}
在接收此字节数组的函数中,我只是将字节数组直接写入文件。
任何帮助将不胜感激。
谢谢!
【问题讨论】:
-
只是为了确定,你不是站在经度 0 度吗? :P
-
哈哈,是的。我已经验证它是 -94.something
标签: ios xamarin.ios xamarin.forms xamarin-studio xamarin.mac