来自图像选择器 swift 3 的 GeoTag 图像 [英] GeoTag Images from image picker swift 3

查看:12
本文介绍了来自图像选择器 swift 3 的 GeoTag 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从图像选择器中选择的图像中获取地理标记位置.我正在使用此代码

I want to get geotag location from image which is selected from image picker. I am using this code

   if picker.sourceType == UIImagePickerControllerSourceType.PhotoLibrary
{
    if let currentLat = pickedLat as CLLocationDegrees?
    {
        self.latitude = pickedLat!
        self.longitude = pickedLong!
    }
    else
    {
    var library = ALAssetsLibrary()
    library.enumerateGroupsWithTypes(ALAssetsGroupAll, usingBlock: { (group, stop) -> Void in
            if (group != nil) {

            println("Group is not nil")
            println(group.valueForProperty(ALAssetsGroupPropertyName))
            group.enumerateAssetsUsingBlock { (asset, index, stop) in
                if asset != nil
                {
                if let location: CLLocation = asset.valueForProperty(ALAssetPropertyLocation) as CLLocation!
                { let lat = location.coordinate.latitude
                    let long = location.coordinate.longitude

                    self.latitude = lat
                    self.longitude = lat

                    println(lat)
                    println(long)
                    }
                }
            }
        } else
            {
            println("The group is empty!")
            }
        })
        { (error) -> Void in
            println("problem loading albums: (error)")
    }
}

}

我想知道在 swift 3 中隐藏此代码.我是使用 swift 3 编码的新手.这将非常有帮助

i want to know to covert this code in swift 3 .I am new in coding with swift 3 .It will be very helpful

推荐答案

经过几个小时的搜索,我得到了答案

After hours of searching i got my ans

   import UIKit
   import Photos

 class ViewController: UIViewController,UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var imageView: UIImageView!

@IBOutlet weak var locationLabel: UILabel!
@IBOutlet weak var timeLabel: UILabel!


@IBOutlet weak var logi: UILabel!

@IBOutlet weak var lati: UILabel!





var lat = String()
var log = String()
var location = String()
 var timeTaken = "Not Known"

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
@IBAction func imagegeo(_ sender: Any) {

    let imagePicker = UIImagePickerController()
    imagePicker.sourceType = .photoLibrary
    imagePicker.delegate = self
    present(imagePicker, animated: true, completion: nil)




}


func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    var chosenImage:UIImage?



    if let URL = info[UIImagePickerControllerReferenceURL] as? URL {
        print("We got the URL as (URL)")
        let opts = PHFetchOptions()
        opts.fetchLimit = 1
        let assets = PHAsset.fetchAssets(withALAssetURLs: [URL], options: opts)

        print(assets)


        for assetIndex in 0..<assets.count {
            let asset = assets[assetIndex]



            location = String(describing: asset.location)



            log = String(describing: asset.location?.coordinate.longitude)

            lat = String(describing: asset.location?.coordinate.latitude)

            timeTaken = (asset.creationDate?.description)!


            print(log)


            print(location)

            print(lat)


        }
    }

    if let editedImage = info[UIImagePickerControllerEditedImage] as? UIImage {
        chosenImage = editedImage
    } else if let selectedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
        chosenImage = selectedImage
    }

    dismiss(animated: true) {
        DispatchQueue.main.async {


            self.imageView.image = chosenImage
            self.timeLabel.text = self.timeTaken


            self.locationLabel.text = self.location
            self.lati.text = self.lat
            self.logi.text = self.log



        }
    }
}

   }

这篇关于来自图像选择器 swift 3 的 GeoTag 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆