2012-04-12 32 views
6

可能重复:
How Do I Get The Correct Latitude and Longitude From An Uploaded iPhone Photo?iPhone iOS如何从相机胶卷图像中提取照片元数据和地理标签信息?

我做一个照片应用程序,并想知道什么是我与地理标记照片的工作选择。 我想显示拍摄照片的位置(类似于照片应用程序)。这可能吗?

此外,我需要知道何时拍摄照片。我可以捕捉到我拍摄的照片的相关信息,但相机胶卷图像呢?

回答

13

是的,这是可能的。

您必须使用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. 

}]; 

这将枚举您的资产组。接下来,您挑选一个组并枚举其资产。

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以获取照片创建的日期和时间。

相关问题