skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    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
         }
    }
    

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search