首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从照片iOS中提取GPS数据

从照片iOS中提取GPS数据
EN

Stack Overflow用户
提问于 2016-01-29 16:48:19
回答 2查看 4.6K关注 0票数 6

我需要从UIImagePickerController采集的照片中获取GPS数据,并提取用于UIMapKit的照片的位置,我尝试了一些堆栈溢出和Google中的示例代码,但它们对我都没有用!我所使用的照片包含纬度和经度数据,但是它总是返回带这个致命错误的nil:“意外地找到了零,而打开了一个可选的值”,我在模拟器上测试了这个应用程序,它会引起什么问题吗?我考虑过各种各样的问题,我是不是做错了什么?这是代码

代码语言:javascript
复制
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: {
       (error: NSError!) in
        NSLog("Error!")

       }

     )} dismissViewControllerAnimated(true, completion: nil)}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-01-29 19:08:52

我找到了解决方案,代码是正确的!但是当我通过拖放将GPS数据从照片中删除时,我会将照片存储到Dropbox中,并通过模拟器的safari下载它们!参考Is it possible to access a photo's geotag metadata from within the simulator?

票数 3
EN

Stack Overflow用户

发布于 2021-04-07 09:17:03

这条路干净多了。

代码语言:javascript
复制
import Photos

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
    guard let asset = info[.phAsset] as? PHAsset else { return }

    // Do whatever
    asset.location?.coordinate.latitude
    asset.location?.coordinate.longitude
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35089796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档