0

So I have this code that allows me to choose an image from the photo library and then display it.

But my question is, how can I access the EXIF data, more specific the latitude and longitude?

Im not that experienced, so I would really appreciate some help

This is the ContentView: https://hatebin.com/omavjsprek

And this is the code for the imagePicker:

struct imagePicker:UIViewControllerRepresentable {
    @Binding var image: UIImage?
    @Binding var showImagePicker: Bool
    
    typealias UIViewControllerType = UIImagePickerController
    typealias Coordinator = imagePickerCoordinator
    
    var sourceType:UIImagePickerController.SourceType = .camera
    
    
    func makeUIViewController(context: UIViewControllerRepresentableContext<imagePicker>) -> UIImagePickerController {
        let picker = UIImagePickerController()
        picker.sourceType = sourceType
        picker.delegate = context.coordinator
        return picker
    }
    
    func makeCoordinator() -> imagePicker.Coordinator {
        return imagePickerCoordinator(image: $image, showImagePicker: $showImagePicker)
    }
    
    func updateUIViewController(_ uiViewController: UIImagePickerController, context: UIViewControllerRepresentableContext<imagePicker>) {}
    
    
}



class imagePickerCoordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
        @Binding var image: UIImage?
        @Binding var showImagePicker: Bool
    
    init(image:Binding<UIImage?>, showImagePicker: Binding<Bool>) {
            _image = image
            _showImagePicker = showImagePicker
    }
    
    
    
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        if let uiimage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
            image = uiimage
            showImagePicker = false
        }
        
        
    }
    
    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        showImagePicker = false
    }


}
Nick
  • 219
  • 4
  • 15
  • The accepted answer here should help: https://stackoverflow.com/questions/9766394/get-exif-data-from-uiimage-uiimagepickercontroller – hayesk Feb 20 '21 at 17:42
  • I looked at the code, but when reading the comments it seems that the EXIF data isn’t actually accessed, but created and then added to the image. But what I dont know, is if this is the case for both images chosen from the library and images taken with the camera. Do you know if this is the case for both or just images taken with the camera? @hayesk – Nick Feb 20 '21 at 18:04

0 Answers0