iPhone iOS 如何从相机胶卷图像中提取照片元数据和地理标记信息?

标签 iphone objective-c ios photo geotagging

<分区>

Possible Duplicate:
How Do I Get The Correct Latitude and Longitude From An Uploaded iPhone Photo?

我正在制作一个照片应用程序,想知道我有哪些处理带有地理标记的照片的选项。 我想显示照片的拍摄地点(类似于照片应用)。这可能吗?

此外,我需要知道照片的拍摄时间。我可以为自己拍摄的照片捕获此信息,但是相机胶卷图像呢?

最佳答案

是的,这是可能的。

您必须使用 ALAssetsLibrary 来访问您的相机胶卷。然后你只需列举你的照片并询问位置。

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.

}];

这将枚举您的 Assets 组。接下来,您选择一个组并枚举其 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];    
 }];

现在您的 loc 变量包含照片拍摄地点的位置。您应该在使用前根据 ALErrorInvalidProperty 检查它,因为有些照片可能缺少此数据。

您可以指定ALAssetPropertyDate来获取照片创建的日期和时间。

关于iPhone iOS 如何从相机胶卷图像中提取照片元数据和地理标记信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10116527/

相关文章:

ios - 在核心数据中单独存储日期值

iphone - 媒体查询和 firefox/chrome

iphone - 我需要释放xib资源吗?

objective-c - 我可以安全地使用这个弱自自动类型的快捷方式吗?

ios - 在NSString中的句号或问号前修剪空格

ios - Swift - 播放与 spotify 并行的声音

iphone - 有什么办法可以阅读国际 App Store 评论吗?

ios - 根据plist文件快速更改标签文本背景颜色

iphone - ios Kill 应用程序问题

objective-c - 表格单元格保持选中状态