2016-09-28 144 views
1

我试图从两个日期范围内的图片库中提取图像,并且I am getting the images successfully如何在iOS中使用PHAsset获取图像的经度和纬度?

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

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格式(获取拉特和长),但得到空输出。

如何获得图像的经纬度?

如果有另一种方式来获得信息,请帮我

预先感谢您

回答

1

您不需要做任何事情,如果你已经有了PHAssets(就像你说的,你有成功检索它们)。

您需要的是.location您的PHAsset的属性。它基本上是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]; 

就是这样,你有字典的经度和纬度。