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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With