【问题标题】:How to get latitude and longitude of an image using PHAsset in iOS?如何在 iOS 中使用 PHAsset 获取图像的纬度和经度?
【发布时间】:2016-09-28 10:23:24
【问题描述】:

我正在尝试从照片库中获取两个日期和I am getting the images successfully 范围内的图像。

我还通过使用以下代码获取图像的信息。

  PHContentEditingInputRequestOptions *options = [[PHContentEditingInputRequestOptions alloc] init];
        options.networkAccessAllowed = YES; //download asset metadata from iCloud if needed

        [asset requestContentEditingInputWithOptions:options completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
            CIImage *fullImage = [CIImage imageWithContentsOfURL:contentEditingInput.fullSizeImageURL];

            //NSLog(@"fullImage=%@", fullImage.properties.description);


        }];

但图像信息以字符串格式提供给我。

我尝试将其转换为 NSDictionary 格式(用于获取 lat 和 long)但得到空输出。

如何获取图像的经纬度?

如果有其他获取信息的方法,请帮助我

提前谢谢你

【问题讨论】:

    标签: ios objective-c uiimage nsdictionary phasset


    【解决方案1】:

    如果您已经拥有 PHAsset,则无需执行任何其他操作(如您所说,您已成功检索它们)。

    您需要的是 PHAsset 的 .location 属性。它基本上是 CLLocation 的一个实例。你可以像这样使用它:

    asset.location.coordinate.longitude
    

    asset.location.coordinate.latitude
    

    由于您已经成功获取了PHFetchResult,现在您需要对其进行迭代以获取 PHAsset 对象,然后如果可用则从中获取位置信息。要以字典的形式从 PHAsset 获取 GPS 信息,请添加此方法:

    -(NSMutableDictionary *) getGPSInformationForAsset: (PHAsset *) asset
    {
        NSString *longitude = [NSString stringWithFormat:@"%f",asset.location.coordinate.longitude];
        NSString *latitude = [NSString stringWithFormat:@"%f",asset.location.coordinate.latitude];
        NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
        [dic setValue:longitude forKey:@"longitude"];//Perform proper validation here for whatever your requirements are
        [dic setValue:latitude forKey:@"latitude"];
        return dic;
    }
    

    现在像这样使用这个方法:

    NSMutableDictionary *coordinatesDictionary = [self  getGPSInformationForAsset:asset];
    

    就是这样,您在字典中找到了纬度和经度。

    【讨论】:

      猜你喜欢
      • 2012-07-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-17
      • 2011-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多