Using UIImagePickerController I am attempting to gather GPS info from the metadata of the image. Here is my code sample:
NSDictionary *imageMetadata = [info objectForKey: UIImagePickerControllerMediaMetadata];
NSLog(@"Working META: %@",imageMetadata);
CGDataProviderRef dataProvider = CGImageGetDataProvider(originalImage.CGImage);
CFDataRef data = CGDataProviderCopyData(dataProvider);
CGImageSourceRef imageSource = CGImageSourceCreateWithData(data, nil);
NSDictionary *metaDict = (__bridge NSDictionary *)(CGImageSourceCopyProperties(imageSource, nil));
NSLog(@"Not WOrking META: %@",metaDict);
In the output from NSLog I can see that Working Meta has all associated content. Unfortunately the Not Working Meta is outputting null. From what I can tell I need to enhance the options on the image source and CFDictionary rather than using nil. Am I on the right path? If so, what change should I make to pull the GPS data through?
Try obtaining your mutable copy of the source EXIF dictionary like this:
Now set GPS data to that EXIF dictionary (code courtesy GusUtils):
And finally you need to populate this data to some destination
At this point the variable
data
should contain all information(image+GPS metadata+other metadata) and you can use thisdata
to store wherever you like.EDIT:
To add core location functionality in your class declare CLLocationManagerDelegate protocol in the header. Instantiate a location manager in your
viewDidLoad
:And implement following methods to gather location info:
Also make sure to stop the service before leaving the VC
Then you can use
self.currentLocation
for your `location variable.EDIT2
Ok its seems that you are already using "NSMutableDictionary+ImageMetadata.h" category from GusUtils. So I have made some modifications to my answer. Please give it a try.