2

可能重复:
如何从上传的 iPhone 照片中获取正确的纬度和经度?

我需要从使用 iPhone 相机拍摄并从相机胶卷中选择的照片中访问地理编码位置(纬度和经度)信息。首先,用相机拍的照片...

使用相机拍摄图像后,我将使用以下代码。然后,我将图像元数据提取出来并将其存储到 NSMutableDictionary 中。但是,我在字典中没有看到任何 GPS 信息……它在哪里???我如何访问这些信息。我也找不到这方面的好文档...

下面的代码:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{    
    // snip out code above to keep this question short.

    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    if([mediaType isEqualToString:(__bridge NSString *)kUTTypeImage])
    {
        // images taken with camera have direct access to the metadata by using UIImagePickerControllerMediaMetadata
        NSMutableDictionary *metadata = [[NSMutableDictionary alloc] initWithDictionary:[info objectForKey:UIImagePickerControllerMediaMetadata]];
        NSLog(@"dictionary: %@", metadata);

        // rest of code snipped out to keep this question short

NSLog 输出以下信息 - 但没有 GPS 信息

dictionary: {
DPIHeight = 72;
DPIWidth = 72;
Orientation = 6;
"{Exif}" =     {
    ApertureValue = "2.970853654340484";
    BrightnessValue = "-1.198278557694757";
    ColorSpace = 1;
    DateTimeDigitized = "2012:04:11 21:55:29";
    DateTimeOriginal = "2012:04:11 21:55:29";
    ExposureMode = 0;
    ExposureProgram = 2;
    ExposureTime = "0.06666666666666667";
    FNumber = "2.8";
    Flash = 24;
    FocalLength = "3.85";
    ISOSpeedRatings =         (
        1000
    );
    MeteringMode = 5;
    PixelXDimension = 2592;
    PixelYDimension = 1936;
    SceneType = 1;
    SensingMethod = 2;
    Sharpness = 1;
    ShutterSpeedValue = "3.911199862602335";
    SubjectArea =         (
        1295,
        967,
        699,
        696
    );
    WhiteBalance = 0;
};
"{TIFF}" =     {
    DateTime = "2012:04:11 21:55:29";
    Make = Apple;
    Model = "iPhone 4";
    Software = "5.0.1";
    XResolution = 72;
    YResolution = 72;
};

我也尝试过使用 ALAssetLibrary 的另一种方式,但是我从不输入我的if语句,只输入else部分 - 这显然会产生与上述相同的信息。结果,没用,因为我仍然没有任何 GPS 数据。

代码如下:

创建@property一个NSMutableDictionary名为photoMetadataDictionary_

然后在 .m 文件中执行以下操作:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.1f) 
    {
        NSURL* assetURL = nil;
        if ((assetURL = [info objectForKey:UIImagePickerControllerReferenceURL])) 
        {
            // I never get here... Not sure why...


            ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
            [library assetForURL:assetURL resultBlock:^(ALAsset *asset)  
                {
                    NSDictionary *metadata = asset.defaultRepresentation.metadata;
                    [photoMetadataDictionary_ addEntriesFromDictionary:metadata];
                }
                    failureBlock:^(NSError *error) 
            {
            }];
        }
        else 
        {
            NSDictionary *metadata = [info objectForKey:UIImagePickerControllerMediaMetadata];
            if (metadata)
            {
                [photoMetadataDictionary_ addEntriesFromDictionary:metadata];
            }
        }
    }
4

0 回答 0