首页 > 解决方案 > iPhone画廊在swift中选择了图像位置

问题描述

我需要根据图库中的图像位置(图像拍摄位置纬度和经度)调用 api。任何人都可以帮助我提供正确的指南或示例代码

标签: iosswift

解决方案


是的,您可以使用资产 API 并获取图像位置,看看下面的示例代码

https://gist.github.com/sumitlni/6421aece205ebefa647abe701d2429e0

// this code will be executed with in callback of 
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]).. 

let opts = PHFetchOptions()
            opts.fetchLimit = 1
            let assets = PHAsset.fetchAssets(withALAssetURLs: [URL], options: opts)
for assetIndex in 0..<assets.count {
let asset = assets[assetIndex]
                // print("Location: \(asset.location?.description) Taken: \(asset.creationDate)")
location = String(describing: asset.location!)
// Here you have the location if it found 
}

推荐阅读