How to get EXIF data(latitude/longitude) from image?

Hi all,
So I have this code where I can choose an image from the photo library and then display it.
My question is, how can i access the EXIF data of that image, more specific the latitude and longitude?

This is my contentView: ContentView.swift · GitHub

And this is the more “relevant” code:

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


I found this article through a search in Google. Perhaps it might give you a pointer…

So i checked out the article and when i tried to run the code in the article just as it is the whole app crashed.
Idk if what he is doing is better, but he is using PHPickerViewController where as i am using UIImagePickerController

I found some posts on StackOverflow that might work, but i have absolutely no idea on how to implement them. Can someone tell me where and how they should be used?

This is one of those codes:

Scroll down the article and download his project from GitHub that contains the UI as shown in the article.

That will run on either a simulator or a real device.