我正在尝试使用自定义相机应用程序为我拍摄的图像添加GPS元数据。我的相机应用程序按预期拍摄图像,每张照片中都包含许多苹果特定的元数据值。但是我似乎无法添加GPS数据。我做错了什么?谢谢。
class ViewController: UIViewController {
var output : AVCaptureStillImageOutput!
var locationManager : CLLocationManager()
override func viewDidLoad()
createCamera()
initLocationManager()
super.viewDidLoad()
}
func createCamera(){
//create camera code. works fine
}
func takePhoto(){
self.output.captureStillImageAsynchronousFromConnection(self.connection){
buffer, error in
if let error = error{
println("Error: \(error)")
}
else{
var imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(buffer)
var metadata = self.getImageMetaData()
var library = ALAssestsLibrary()
library.writeImageDataToSavedPhotosAlbum(imageData, metadata, completionBlock: {
(assetURL: NSURL!, error: NSError!) -> Void in
})
}
}
}
func getImageMetadata() -> NSMutableDictionary{
var locDict = NSMutableDictioary()
locDict.setObject(self.locationManager.location.timestamp, forKey: "KCGImagePrropertyGPSTimeStamp")
locDict.setObject("N", forKey: kCGImagePropertyGPSLatitudeRef")
locDict.setObject(self.locationManager.location.coordinate.latitude, forKey: "kCGImagePropertyGPSLatitude")
locDict.setObject("W", forKey: "kCGImagePropertyGPSLongitudeRef")
locDict.setObject(self.locationManager.location.coordinate.longitude, forKey: "kCGImagePropertyGPSLongitude")
return locDict
//this returns the correct coordinates
//NOTE: I hard coded the Ref values for brevity.
}
}
注意:我使用ExifTool来查看元数据。