Reputation: 1284
Sir, Here i need to add geolocation from metadata to uiimage but after adding i just loading in to photoalbum only but here i need that image,here i have added the source code
- (void) saveImage:(UIImage *)imageToSave withInfo:(NSDictionary *)info
{
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Get the image metadata (EXIF & TIFF)
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
[defaults objectForKey:latkey];
float longitude=[defaults floatForKey:longkey];
float latitude=[defaults floatForKey:latkey];
CLLocation * loc=[[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
NSMutableDictionary *metaDict = nil;
if ([info objectForKey:UIImagePickerControllerOriginalImage] != nil) {
metaDict = [NSMutableDictionary dictionaryWithDictionary:[info objectForKey:UIImagePickerControllerMediaMetadata]];
NSDictionary *gpsDict = [self currentLocation:loc];
if ([gpsDict count] > 0) {
[metaDict setObject:gpsDict forKey:(NSString*)kCGImagePropertyGPSDictionary];
}
}
[library writeImageToSavedPhotosAlbum:[imageToSave CGImage] metadata:metaDict completionBlock:^(NSURL *newURL, NSError *error) {
if (error) {
} else {
}
}];
NSLog(@"metaDict :%@",metaDict);
NSURL *referenceURL = [info objectForKey:UIImagePickerControllerReferenceURL];
[library assetForURL:referenceURL resultBlock:^(ALAsset *asset) {
ALAssetRepresentation *rep = [asset defaultRepresentation];
NSDictionary *metadata = rep.metadata;
NSLog(@"%@", metadata);
CGImageRef iref = [rep fullScreenImage] ;
if (iref) {
capturedImage.image = [UIImage imageWithCGImage:iref];
}
} failureBlock:^(NSError *error) {
// error handling
}];
}
Creates an EXIF field for the current geo location.
- (NSMutableDictionary*)currentLocation:(CLLocation *)location{
NSMutableDictionary *locDict = [[NSMutableDictionary alloc] init];
if (location != nil) {
CLLocationDegrees exifLatitude = location.coordinate.latitude;
CLLocationDegrees exifLongitude = location.coordinate.longitude;
[locDict setObject:location.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];
}
please help me
Upvotes: 2
Views: 2898
Reputation: 38239
EDIT : U can get image add in photo Album like by following this link.
Now if u have asset then using asset's created date u can know last photo added like this as save date before adding to photo album :
NSDate *imgCreateddate = [asset valueForProperty:ALAssetPropertyDate];
if(imgCreateddate isGreaterThan savedDate)
{
last Photo;
}
Refer Adding metadata to iOS images the easy way link.
Refer GusUtils for sample code.
Refer saving-geotag-info-with-photo link
Upvotes: 1