2

I'm having a problem while getting the latitude and longitude data from an image(which is having geo location details). I have imported the EXIF framework and I'm using the following code to achieve this:

 NSData *jpegData = [UIImageJPEGRepresentation(image, 0.5) base64String];
EXFJpeg* jpegScanner = [[EXFJpeg alloc] init];
[jpegScanner scanImageData: jpegData];
EXFMetaData* exifData = jpegScanner.exifMetaData;
id latitudeValue = [exifData tagValue:[NSNumber numberWithInt:EXIF_GPSLatitude]];
id longitudeValue = [exifData tagValue:[NSNumber numberWithInt:EXIF_GPSLongitude]];
NSLog(@"Longitude: %@  Longitude: %@", latitudeValue, longitudeValue);

But its returning the NULL value for both latitude and longitude, can anyone please tell me what I'm doing wrong in the above code? Please help me out. Thanks in Advance!!

Andrews J
  • 187
  • 12

2 Answers2

1

You can do it with the framework.

ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc]init];
[assetsLibrary assetForURL:photoUrl resultBlock:resultBlock failureBlock:nil];
ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset *photoAsset) {        
    CLLocation *location = [photoAsset valueForProperty:ALAssetPropertyLocation];

    NSMutableDictionary *exifDataDict = [[NSMutableDictionary alloc] init];
    if (location != nil) {
        [exifDataDict setObject:[NSNumber numberWithDouble:location.coordinate.latitude] forKey:@"latitude"];
        [exifDataDict setObject:[NSNumber numberWithDouble:location.coordinate.longitude] forKey:@"longitude"];
    }
}
Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
Apurv
  • 17,116
  • 8
  • 51
  • 67
0

I had a similar issue once. While dealing with it I got the impression that UIImage sort of strips all or some of the EXIF data. EXIFJpeg worked fine for me when the image data was read from file, boundle or webservice etc. direclty but I did not manage to extract any reasonalbe EXIFs when I stored the image in memory as UIImage object and then used UIImageJPEGRepresentaiion to get the image data and the EXIF from that data.

I will not sign this in blood but that was my impression and using the "raw" data from file did actually work for me. So I received the file from some server, then extracted the EXIF including geo tags (if any) and after that created the UIImage.

Hermann Klecker
  • 14,039
  • 5
  • 48
  • 71