IPhone iOS, how to extract photo metadata and geotag information from camera roll image?

Possible duplicate:
How to get the correct latitude and longitude from a downloaded iPhone photo?

I am doing a photo application and want to know what my options for working with geotags are. I would like to show where the photo was taken (similar to the application of photos). Is it possible?

In addition, I need to know when the photo was taken . I can capture this information for photos that I take myself, but what about camera images?

+6
source share
1 answer

Yes it is possible.

You must use ALAssetsLibrary to access your camera roll. Then you simply list your photos and request a 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 list your asset groups. Then you select a group and list 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]; }]; 

Your loc variable now contains the location of the place where the photo was taken. Before use, you should check it for ALErrorInvalidProperty , as some photos may not have this data.

You can specify ALAssetPropertyDate to get the date and time the photo was taken.

+13
source

Source: https://habr.com/ru/post/912992/


All Articles