iPhone画廊在swift中选择了图像位置

时间:2018-05-02 06:41:01

标签: ios swift

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

1 个答案:

答案 0 :(得分:0)

是的,您可以使用资产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 
}