Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract GPS data from photo

Tags:

ios

swift

ios8

I have a hard time because I want to extract the GPS coordinates from a photo. I use the function imagePickerController:didFinishPickingMediaWithInfo to pick an image and the I am inserting that image in a collectionView using the new Photos framework. I want to extract the GPS coordinates from the photo. I have done some research and I am aware of the fact that UIImage does not contain all the metadata, so I tried using the AssetsLibrary framework. Inside didFinishPickingMediaWithInfo I am using the following code to extract the photo location:

    var referenceURL : NSURL = info.objectForKey(UIImagePickerControllerReferenceURL) as NSURL
    var library : ALAssetsLibrary = ALAssetsLibrary()
    library.assetForURL(referenceURL, resultBlock: { (asset : ALAsset!) -> Void in
        var rep : ALAssetRepresentation = asset.defaultRepresentation()
        var metadata : NSDictionary = rep.metadata()


        let location: AnyObject! = asset.valueForProperty(ALAssetPropertyLocation)
        if location != nil {
            println(location)
        }
        else
        {
            println("Location not found")
        }


         })
    {
            (error : NSError!) -> Void in
    }

However, it doesn't find the location, even though I checked the image and it contains EXIF metadata (it contains also GPS locations, in which I am interested in). How can I retrieve the coordinates from photo?

like image 869
Cristian Avatar asked Nov 05 '14 15:11

Cristian


People also ask

How do I find out the GPS of a photo?

Here are a few ways to get the GPS information from your photos. If you’re using a Mac, you can access your GPS information by simply right clicking on the photo file you want to view and then picking “get info.” This will bring up a box showing all of the EXIF data attached to that particular image file.

How do I extract metadata from a photo?

The following code can be used to extract metadata from a photo. This code snippet extracts the metadata from an image-’ img.jpg ’ and store the data as a dictionary named exif_table. I have written an article detailing each step in extracting the EXIF data which can be accessed below.

Why is photo GPS extract not working on Google Maps?

Important Message: In 2018 Google changed its pricing policy for the usage of the Google Maps. Because of this, all versions of Photo GPS Extract up to version 7 will stop functioning properly as the Google now requires applications to have an (paid) API-key.

How do I extract Exif data from a photo?

As I’m sure you know, or at least can imagine, photos often contain a lot of meta data “under the hood”. This is called EXIF data and contains info such as the device maker (e.g. Samsung), device model, date and time the photo was taken, GPS location data, and a lot of other stuff. With exif.js we can easily use JavaScript to extract this data.


1 Answers

With iOS 11 everything becomes much easier to recover GPS coordinate from a picture in your photo roll.

First import the Photo SDK

import Photos

Then before pushing the UIImagePickerController, ask the authorisation to access the data :

if PHPhotoLibrary.authorizationStatus() == .notDetermined {
    PHPhotoLibrary.requestAuthorization { [weak self](_) in
        // Present the UIImagePickerController
        self?.present(picker, animated: true, completion: nil)
    }
}

Then when you grab back the image from the UIImagePickerController, you only need to do the following to grab the coordinates :

let coordinate = (info[UIImagePickerControllerPHAsset] as? PHAsset)?.location?.coordinate
like image 107
jfgrang Avatar answered Nov 15 '22 17:11

jfgrang