小编Sam*_*ira的帖子

从照片 iOS swift 中提取 GPS 数据

我需要从 UIImagePickerController 选择的照片中获取 GPS 数据并提取要在 UIMapKit 中使用的照片的位置,我在 stackoverflow 和 Google 中尝试了一些示例代码,但没有一个对我有用!我使用的照片包含纬度和经度数据,但它总是返回 nil 并出现这个致命错误:“在展开可选值时意外发现 nil”,我在模拟器上测试应用程序是否会导致任何问题?我考虑了各种各样的问题,我哪里做错了?这是代码

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

    if picker.sourceType == UIImagePickerControllerSourceType.PhotoLibrary {

       let url: AnyObject? = info[UIImagePickerControllerReferenceURL] as? NSURL

       let library = ALAssetsLibrary()
                    library.assetForURL(url as NSURL, resultBlock: { (asset: ALAsset!) -> Void in
           if asset != nil {
           var assetRep: ALAssetRepresentation = asset.defaultRepresentation()
           var metaData: NSDictionary = assetRep.metadata()
           let location = metaData.objectForKey(ALAssetPropertyLocation) as CLLocation!
           let lat = location.coordinate.latitude
           let long = location.coordinate.longitude
           }
  }, failureBlock: { …
Run Code Online (Sandbox Code Playgroud)

gps latitude-longitude uiimagepickercontroller ios swift

6
推荐指数
1
解决办法
3645
查看次数