now available

now available
Want fresh tech tips in your inbox?

How to Get GPS Location Information from a Photo or Movie with Swift and UIImagePickerController


This code assumes you're using the UIImagePickerController. If not you will need to get an image url another way.

But, If you are using UIImagePickerControllerDelegate then it will supply the asset's url in the info dictionary . From the asset's url you can fetch the asset with PHAsset.fetchAssets method.

Anyway, once you get the array your asset will contain the location.

class ViewController: UIViewController, UIImagePickerControllerDelegate {
  // *** omitted details for implentation of UIImagePickerController *** //

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    if let url = info[UIImagePickerControllerReferenceURL] as? URL {
                if let asset: PHAsset = PHAsset.fetchAssets(withALAssetURLs: [url], options: nil)[0] {
                    print(asset.location ?? "None")
        dismiss(animated: true, completion:nil) // hide picker when done w/it.
Tagged w/ #swift #swift3 #image #assets #gps #location #ios #macos #apple

Apps I've Built

XPath Expression Editor
Practice and improve your XPath skills with XPath Editor
Click to buy on the App Store
Photo Location Changer
Easily change the location on your photos and videos
Click here for more info about the app
Photo Date Changer
Easily change the dates and times on your photos and videos
Click here for more info about the app
English dictionary with notifications so you won't forget what you're studying!
Click here for more info about the app
The app that quizzes and scores you on your vocabulary!
Click here for more info about the app