3

I used AVFoundation to capture an image in a UIView and add comments to it. Now, I need to get the geolocation of the captured image. My current code snippet is as shown below. The metadata does not have the geolocation. Maybe I will have to use CLLocation? Please guide me ASAP.

[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
 {
     CFDictionaryRef metadataDict = CMCopyDictionaryOfAttachments(NULL, imageSampleBuffer, kCMAttachmentMode_ShouldPropagate);
     NSMutableDictionary *metadata = [[NSMutableDictionary alloc] initWithDictionary:(__bridge NSDictionary*)metadataDict];
     CFRelease(metadataDict);
     NSLog(@"%@",metadata);
     CFDictionaryRef exifAttachments = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
     if (exifAttachments)
     {
         // Do something with the attachments.
     }
     else
         NSLog(@"no attachments");

     NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
     [captureSession stopRunning];
     [imageData writeToFile:path atomically:YES];
 }];
ilight
  • 1,622
  • 2
  • 22
  • 44

1 Answers1

0

From what I can tell, you have to wrap you're own metadata dictionary and add it to the image data.

Here is a class extension (By Gustavo, link below) that handles writing EXIF and geolocation data to photos captured using the AVCaptureStillImageOutput apis: https://github.com/gpambrozio/GusUtils/blob/master/GusUtils/NSMutableDictionary+ImageMetadata.m

Also, here is Gustavo's article that explains the implementation: http://blog.codecropper.com/2011/05/adding-metadata-to-ios-images-the-easy-way/

HTH

Glavid
  • 1,071
  • 9
  • 19