Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had exactly the same problem. I think the documentation on this topic isn't great, so I solved it in the end by looking at the metadata of a photo taken by the Camera app and trying to replicate it.</p> <p>Here's a run down of the properties the Camera app saves:</p> <ul> <li>kCGImagePropertyGPSLatitude <strong>(NSNumber)</strong> <em>(Latitude in decimal format)</em></li> <li>kCGImagePropertyGPSLongitude <strong>(NSNumber)</strong> <em>(Longitude in decimal format)</em></li> <li>kCGImagePropertyGPSLatitudeRef <strong>(NSString)</strong> <em>(Either N or S)</em></li> <li>kCGImagePropertyGPSLongitudeRef <strong>(NSString)</strong> <em>(Either E or W)</em></li> <li>kCGImagePropertyGPSTimeStamp <strong>(NSString)</strong> <em>(Of the format 04:30:51.71 (UTC timestamp))</em></li> </ul> <p>If you stick to these you should be fine. Here's a sample:</p> <pre><code>CFDictionaryRef metaDict = CMCopyDictionaryOfAttachments(NULL, imageDataSampleBuffer, kCMAttachmentMode_ShouldPropagate); CFMutableDictionaryRef mutable = CFDictionaryCreateMutableCopy(NULL, 0, metaDict); NSDictionary *gpsDict = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithFloat:self.currentLocation.coordinate.latitude], kCGImagePropertyGPSLatitude, @"N", kCGImagePropertyGPSLatitudeRef, [NSNumber numberWithFloat:self.currentLocation.coordinate.longitude], kCGImagePropertyGPSLongitude, @"E", kCGImagePropertyGPSLongitudeRef, @"04:30:51.71", kCGImagePropertyGPSTimeStamp, nil]; CFDictionarySetValue(mutable, kCGImagePropertyGPSDictionary, gpsDict); // Get the image NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; UIImage *image = [[UIImage alloc] initWithData:imageData]; // Get the assets library ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; [library writeImageToSavedPhotosAlbum:[image CGImage] metadata:mutable completionBlock:captureComplete]; </code></pre> <p>This is all in the completionHandler of the captureStillImageAsynchronouslyFromConnection method of your AVCaptureConnection object, and self.currentLocation is just a CLLocation. I hardcoded the timestamp and Lat/Lng Refs for the example to keep things simple.</p> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload