如何在iOS中使用PHAsset获取图像的纬度和经度? [英] How to get latitude and longitude of an image using PHAsset in iOS?

查看:225
本文介绍了如何在iOS中使用PHAsset获取图像的纬度和经度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从两个日期和 我已成功获取图像.

I am trying to fetch images from photo library within the range of two dates and I am getting the images successfully.

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

And I am also getting the info of the image by using below code.

  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);


        }];

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

But image info giving me in string format.

我尝试将其转换为 NSDictionary 格式(用于获取经纬度),但输出为空.

I tried to convert it into NSDictionary format(for get lat and long) but getting null output.

如何获得图像的经纬度?

How can get lat and long of image ?

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

if there is an another way to get info please help me

提前致谢

推荐答案

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

You don't need to do anything else if you already have the PHAssets (As you say, you have successfully retrieved them).

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

What you need is .location property of your PHAsset. It is basically an instance of CLLocation. You can use it like:

asset.location.coordinate.longitude

asset.location.coordinate.latitude

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

Since you have already gotten your PHFetchResult successfully, now you need to iterate over it to get PHAsset object and then get location info from it if available. To get GPS Info from PHAsset in form of dictionary, add this method:

-(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];

就是这样,您在字典中获得了纬度和经度.

That's it, You got the Latitude and Longitude in a dictionary.

这篇关于如何在iOS中使用PHAsset获取图像的纬度和经度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆