2016-09-28 149 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]; 

就是這樣,你有字典的經度和緯度。