如何在iOS中使用PHAsset获取图像的经纬度?
How to get latitude and longitude of an image using PHAsset in iOS?
我正在尝试从照片库中获取两个日期和 范围内的图像。
而且我还使用以下代码获取图像的信息。
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 格式(用于获取纬度和经度),但输出为空。
如何获取图像的经纬度?
如果有其他获取信息的方法请帮助我
提前致谢
如果您已经拥有 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];
就是这样,您在字典中得到了纬度和经度。
我正在尝试从照片库中获取两个日期和
而且我还使用以下代码获取图像的信息。
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 格式(用于获取纬度和经度),但输出为空。
如何获取图像的经纬度?
如果有其他获取信息的方法请帮助我
提前致谢
如果您已经拥有 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];
就是这样,您在字典中得到了纬度和经度。