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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With