Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 991
Alex Stone Avatar asked Apr 12 '12 02:04

Alex Stone


People also ask

Can you get location data from iPhone photos?

See where a photo was takenOpen a photo, then swipe up to see photo information. Tap the map or address link to see more details. To change the location or address where the photo was taken, see Change the date, time, or location.

Does iPhone save metadata on photos?

Nearly every photo you take on your iPhone has a batch of hidden information stored within: metadata. This metadata, known more specifically as EXIF data for images, contains descriptive information that makes each image unique. That includes the creation date, camera information and settings and your location.


1 Answers

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.

like image 146
anticyclope Avatar answered Sep 19 '22 02:09

anticyclope