有什么方法可以将 GPS 信息写入一张图片中吗? 例如,我想开发一个可以拍摄带有位置信息的照片的相机应用程序。 我可以使用 PhotoKit 相关方法或其他一些方法(例如 ImageIO)吗? 谢谢。
最佳答案
您可以像这样向图像添加位置信息
let locationCordinate = CLLocationCoordinate2DMake(lat, long)
let currentDate = NSDate()
let imageLocation = CLLocation(coordinate: locationCordinate, altitude: 0.0, horizontalAccuracy: 0.0, verticalAccuracy: 0.0, timestamp: currentDate)
之后,您可以将此位置添加到您的图像中,如下所示
PHPhotoLibrary.sharedPhotoLibrary().performChanges({
let assetLocationChangeRequest = PHAssetChangeRequest(forAsset: lastImageAsset)
assetLocationChangeRequest.location = imageLocation
}, completionHandler: {
(success:Bool, error:NSError?) -> Void in
if (success) {
print("Succesfully saved location to image")
} else {
print("Failed to save with Error : \(error!)")
}
})
关于ios - 如何使用PHPhotoKit将CLLocation的GPS信息写入UIImage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40777333/