gpt4 book ai didi

ios - 带有 GPS 数据的 imagePickerController (Swift)

转载 作者:搜寻专家 更新时间:2023-10-30 21:59:37 25 4
gpt4 key购买 nike

如果有人能提供帮助,我要感谢。我正在从 https://www.youtube.com/watch?v=ztIBNHOm35E 学习这个非常好的快速示例代码或 https://github.com/TDAbboud/PhotosGalleryApp

我正在关注所选相机胶卷照片中的 GPS 数据。该App需要使用imagePickerController选取任意一张照片放入App相册。但是以下功能(从相机胶卷中选择照片然后放入应用相册)中缺少 GPS 数据。

我的问题:是如何使用 imagePickerController 包含 GPS 在新相册中创建照片/图像。

Code Here

//UIImagePickerControllerDelegate Methods 
func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info: NSDictionary!){

// http://stackoverflow.com/questions/26391158/getting-metadata-in-swift-by-uiimagepickercontroller?rq=1
let metadata = info[UIImagePickerControllerMediaMetadata] as? NSDictionary //Try to get gps info
let image = info[UIImagePickerControllerOriginalImage] as? UIImage
//Implement if allowing user to edit the selected image
//let editedImage = info.objectForKey("UIImagePickerControllerEditedImage") as UIImage

let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT
dispatch_async(dispatch_get_global_queue(priority, 0), {
PHPhotoLibrary.sharedPhotoLibrary().performChanges({
let createAssetRequest = PHAssetChangeRequest.creationRequestForAssetFromImage(image)
let assetPlaceholder = createAssetRequest.placeholderForCreatedAsset
let albumChangeRequest = PHAssetCollectionChangeRequest(forAssetCollection: self.assetCollection, assets: self.photosAsset)!
albumChangeRequest.addAssets([assetPlaceholder!])
}, completionHandler: {(success, error)in
dispatch_async(dispatch_get_main_queue(), {
NSLog("Adding Image to Library -> %@", (success ? "Sucess":"Error!"))
picker.dismissViewControllerAnimated(true, completion: nil)
})
})

})
}
func imagePickerControllerDidCancel(picker: UIImagePickerController!){
picker.dismissViewControllerAnimated(true, completion: nil)
}
}

最佳答案

试试这个:

记得导入AssetsLibrary

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
picker.dismissViewControllerAnimated(true, completion: { () in
if (picker.sourceType == .PhotoLibrary) {
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
let library = ALAssetsLibrary()
var url: NSURL = info[UIImagePickerControllerReferenceURL] as! NSURL

library.assetForURL(url, resultBlock: { (asset: ALAsset!) in
if asset.valueForProperty(ALAssetPropertyLocation) != nil {
let latitude = (asset.valueForProperty(ALAssetPropertyLocation) as! CLLocation!).coordinate.latitude
let longitude = (asset.valueForProperty(ALAssetPropertyLocation) as! CLLocation!).coordinate.longitude
println("\(latitude), \(longitude)")
}
},
failureBlock: { (error: NSError!) in
println(error.localizedDescription)
})
}
})
}

关于ios - 带有 GPS 数据的 imagePickerController (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27275173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com