如何在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格式(用于获取lat和long)但获得null输出。

如何获得拉特和长图像?

如果有另一种方式获取信息,请帮助我

先谢谢你

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

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

 asset.location.coordinate.longitude 

要么

 asset.location.coordinate.latitude 

由于您已经成功获得了PHFetchResult ,现在需要迭代它以获取PHAsset对象,然后从中获取位置信息(如果可用)。 要以字典的forms从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]; 

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