Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is code to copy all available information from a CLLocation object into the proper format for a GPS metadata dictionary:</p> <pre><code>- (NSDictionary *)getGPSDictionaryForLocation:(CLLocation *)location { NSMutableDictionary *gps = [NSMutableDictionary dictionary]; // GPS tag version [gps setObject:@"2.2.0.0" forKey:(NSString *)kCGImagePropertyGPSVersion]; // Time and date must be provided as strings, not as an NSDate object NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"HH:mm:ss.SSSSSS"]; [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; [gps setObject:[formatter stringFromDate:location.timestamp] forKey:(NSString *)kCGImagePropertyGPSTimeStamp]; [formatter setDateFormat:@"yyyy:MM:dd"]; [gps setObject:[formatter stringFromDate:location.timestamp] forKey:(NSString *)kCGImagePropertyGPSDateStamp]; [formatter release]; // Latitude CGFloat latitude = location.coordinate.latitude; if (latitude &lt; 0) { latitude = -latitude; [gps setObject:@"S" forKey:(NSString *)kCGImagePropertyGPSLatitudeRef]; } else { [gps setObject:@"N" forKey:(NSString *)kCGImagePropertyGPSLatitudeRef]; } [gps setObject:[NSNumber numberWithFloat:latitude] forKey:(NSString *)kCGImagePropertyGPSLatitude]; // Longitude CGFloat longitude = location.coordinate.longitude; if (longitude &lt; 0) { longitude = -longitude; [gps setObject:@"W" forKey:(NSString *)kCGImagePropertyGPSLongitudeRef]; } else { [gps setObject:@"E" forKey:(NSString *)kCGImagePropertyGPSLongitudeRef]; } [gps setObject:[NSNumber numberWithFloat:longitude] forKey:(NSString *)kCGImagePropertyGPSLongitude]; // Altitude CGFloat altitude = location.altitude; if (!isnan(altitude)){ if (altitude &lt; 0) { altitude = -altitude; [gps setObject:@"1" forKey:(NSString *)kCGImagePropertyGPSAltitudeRef]; } else { [gps setObject:@"0" forKey:(NSString *)kCGImagePropertyGPSAltitudeRef]; } [gps setObject:[NSNumber numberWithFloat:altitude] forKey:(NSString *)kCGImagePropertyGPSAltitude]; } // Speed, must be converted from m/s to km/h if (location.speed &gt;= 0){ [gps setObject:@"K" forKey:(NSString *)kCGImagePropertyGPSSpeedRef]; [gps setObject:[NSNumber numberWithFloat:location.speed*3.6] forKey:(NSString *)kCGImagePropertyGPSSpeed]; } // Heading if (location.course &gt;= 0){ [gps setObject:@"T" forKey:(NSString *)kCGImagePropertyGPSTrackRef]; [gps setObject:[NSNumber numberWithFloat:location.course] forKey:(NSString *)kCGImagePropertyGPSTrack]; } return gps; } </code></pre> <p>Assign the dictionary returned by this method as the value for the <code>kCGImagePropertyGPSDictionary</code> key in the metadata dictionary you pass to <code>writeImageDataToSavedPhotosAlbum:metadata:completionBlock:</code> or <code>CGImageDestinationAddImage()</code>.</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.
 

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