简体   繁体   中英

How to set the location for the captured photo by using UIImagePickerController

How to set the location for the captured photo by using UIImagePickerController?

I have an app that has the option to take a photo or grab one from the phones gallery. If I selsct one from the gallery I can see the GPS data in the info[UIImagePickerControllerReferenceURL], but when I save it to the apps documents folder it loses the GPS data. If I take a photo from within the app the info[UIImagePickerControllerReferenceURL] is nil?

So, I assuming you want to fetch Metadata Information - Try the following snippet for this- Get UIImage MetaData

I did lots of RND and searched here and there and tried many solutions but no luck, after googling for hours

Finally figured out with the help of https://developer.apple.com/documentation/photokit/phassetchangerequest?language=objc

public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    picker.dismiss(animated: true)
    self.imageToSave = info[.originalImage] as? UIImage
    try? PHPhotoLibrary.shared().performChangesAndWait {
        let imgReq = PHAssetChangeRequest.creationRequestForAsset(from: self.imageToSave!)
        imgReq.location = self.location
        imgReq.isFavorite = true
     }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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