Search code examples
iphoneiosuiimagecllocationgeotagging

iPhone iOS how to add geotagging info to a PNG file?


I'm building a camera effects app and would like to be able to add geo tagging to the screenshots that I capture. I'm grabbing camera images from an AVCaptureSession frame buffer and am displaying them to the user after some processing. The end result is a PNG screenshot. How can I take a CLLocation object and add it to a PNG image?

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
    //how to add geotagging to this method?
       [self performImageCaptureFrom:sampleBuffer];

} 

Thank you!


Solution

  • You can follow this post to add the exif data to the png image. How to write exif metadata to an image (not the camera roll, just a UIImage or JPEG) Note that the user must have already allowed location services for your app. If you are processing the image or letting the user do so, you might find it easier to add the metadata before the final save (which will allow you to not consume double memory by not reopening the image twice, and also since I don't know what kind of processing you are doing the Geo-tagging wont be lost during it).