iPhone iOS how to extract photo metadata and geotagging info from a camera roll image?

geotagging, ios, iphone, objective-c, photo

Solution

Yes, it is possible.

You have to use `ALAssetsLibrary` to access your camera roll. Then you just enumerate through your photos and asks for location.

assetsLibrary = [[ALAssetsLibrary alloc] init];
groups = [NSMutableArray array];

[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos  usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
    if (group == nil)
    {
        return;
    }

    [groups addObject:group];

} failureBlock:^(NSError *error)
{
    // Possibly, Location Services are disabled for your application or system-wide. You should notify user to turn Location Services on. With Location Services disabled you can't access media library for security reasons.

}];

This will enumerate your assets groups. Next, you pick up a group and enumerate its assets.

ALAssetGroup *group = [groups objectAtIndex:0];
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
 {
     if (result == nil)
     {
         return;
     }

     // Trying to retreive location data from image
     CLLocation *loc = [result valueForProperty:ALAssetPropertyLocation];    
 }];

Now your `loc` variable contains location of the place where the photo was taken. You should check it against `ALErrorInvalidProperty` before use, since some photos might lack this data.

You can specify `ALAssetPropertyDate` to obtain the date and time of photo creation.

Problem

Possible Duplicate: How Do I Get The Correct Latitude and Longitude From An Uploaded iPhone Photo? I'm making a photo app and would like to know what are my options for working with geotagged photos. I would like to display where a photo has been taken (similar to photos app). Is this possible? Additionally, I need to know when the picture has been taken. I can capture this info for the pictures that I take myself, but what about the camera roll images?

Original source

Related problems