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