将地理位置数据保存到照片库Swift 3 [英] Save photo with geolocation data to photo library Swift 3

查看:110
本文介绍了将地理位置数据保存到照片库Swift 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用地理位置元数据将照片保存到照片库?

How can I save a photo to photo library with geolocation metadata?

我已请求(并允许)该应用访问用户位置:

I have requested (and allowed) the app to access user location:

private func allowAccessToUserLocation() {

        locationManager = CLLocationManager()
        locationManager.delegate = self
        locationManager.requestWhenInUseAuthorization()
    }

我是否需要询问具体的预备相机应用程序?

Do I need to ask for specific premissions for the camera app?

编辑:

我使用UIImagePickerController从内部拍摄照片该应用程序。
从应用程序中拍摄的所有照片都存储在照片库中,没有地理位置。

I use UIImagePickerController to take photos from within the app. All photos taken from within the app are stored in the photo library WITHOUT the geolocation.

是否与我将图像保存到的方式有关照片库?
我的问题在这里而不是核心位置权限吗?

Does it have anything to do with the way I save the image to photo library? Is my problem here rather than in the core location permissions??

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage{
            UIImageWriteToSavedPhotosAlbum(pickedImage, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)

            dismiss(animated: true, completion: {

                self.showPhoto()})
        }
    }


推荐答案

我想你需要先调用用户的位置才能调用 func addAsset(image:UIImage,location:CLLocation?= nil){...}

Well I guess you need to access the location of the user first before you call func addAsset(image: UIImage, location: CLLocation? = nil) {...}

所以 func中的某个地方imagePickerController(_ picker:UIImagePickerController,didFinishPickingMediaWithInfo info:[String:Any]){ ....}

我打电话:

 let locationManager = CLLocationManager()

        if CLLocationManager.locationServicesEnabled() {
            locationManager.delegate = self
            locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
            locationManager.startUpdatingLocation()

        }
        else{
            //Location service disabled"
        }
        //and then call....

        addAsset(image: pickedImage, location: locationManager.location)

一旦我完成使用:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {...}

我停止更新位置:

 locationManager.stopUpdatingLocation()

这对我有用

这篇关于将地理位置数据保存到照片库Swift 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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