经过一番搜索,我发现并适应这个
这原来cclocation数据到合适的NSDictionary
#import <ImageIO/ImageIO.h>
+(NSMutableDictionary *)updateExif:(CLLocation *)currentLocation{
NSMutableDictionary* locDict = [[NSMutableDictionary alloc] init];
CLLocationDegrees exifLatitude = currentLocation.coordinate.latitude;
CLLocationDegrees exifLongitude = currentLocation.coordinate.longitude;
[locDict setObject:currentLocation.timestamp forKey:(NSString*)kCGImagePropertyGPSTimeStamp];
if (exifLatitude <0.0){
exifLatitude = exifLatitude*(-1);
[locDict setObject:@"S" forKey:(NSString*)kCGImagePropertyGPSLatitudeRef];
}else{
[locDict setObject:@"N" forKey:(NSString*)kCGImagePropertyGPSLatitudeRef];
}
[locDict setObject:[NSNumber numberWithFloat:exifLatitude] forKey:(NSString*)kCGImagePropertyGPSLatitude];
if (exifLongitude <0.0){
exifLongitude=exifLongitude*(-1);
[locDict setObject:@"W" forKey:(NSString*)kCGImagePropertyGPSLongitudeRef];
}else{
[locDict setObject:@"E" forKey:(NSString*)kCGImagePropertyGPSLongitudeRef];
}
[locDict setObject:[NSNumber numberWithFloat:exifLongitude] forKey:(NSString*) kCGImagePropertyGPSLongitude];
return [locDict autorelease];
}
然后我把它添加到您通过相机获得现有的元数据(不默认情况下,具备GPS数据)
我得到这样
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
[imageMetaData setDictionary:[[info objectForKey:UIImagePickerControllerMediaMetadata] copy]];
}
原来的元数据
然后我添加上一个方法产生的gps字典。
[imageMetaData setObject:currentLocation forKey:(NSString*)kCGImagePropertyGPSDictionary];
[library writeImageToSavedPhotosAlbum:[viewImage CGImage] metadata:imageMetaData completionBlock:photoCompblock];
很好的回答,+ 1,但你设置' kCGImagePropertyGPSTimeStamp'错误。该值必须是NSString而不是NSDate。 – Anomie 2011-03-15 16:17:22
你不需要复制'UIImagePickerControllerMediaMetadata'对象的字典;告诉可变字典设置自己以匹配另一个字典将修改接收字典,以便字典变成副本。您使用'copy'消息制作的副本被浪费;更糟糕的是,既然你不释放它,你就会泄漏它。你可以通过释放或者自动释放来解决这个问题,但是最好不要把不必要的拷贝放在第一位。 – 2011-05-01 05:08:20