繁体   English   中英

你如何获得UIImage的地理坐标?

[英]How do you get a UIImage's geographic coordinates?

在UIImagePickerController中拍摄照片后,如何获取UIImage的GPS坐标? 图像是否包含其元数据中的坐标,还是应该为图像及其坐标创建一个类并保存? 谢谢。

请试着看看这个并按照那个答案说的做。

我做到了,并取得了成功..

希望这对你有用..

实际上,您可以在拍摄照片后立即访问图像的元数据。 选择图像后系统调用的协议方法是,

(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

NSDictionary参数info包含一个键:UIImagePickerControllerMediaMetadata

AFAIK,您将需要CLLocationManager来获取当前位置并对其进行地理标记。

iOS 8开始,您可以使用Photos Framework

  func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
  let url = info[UIImagePickerControllerReferenceURL] as? URL
        if url != nil {

            let fetchResult = PHAsset.fetchAssets(withALAssetURLs: [url!], options: nil)
            let asset = fetchResult.firstObject
            print(asset?.location?.coordinate.latitude)
            print(asset?.creationDate)
        }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM