簡體   English   中英

如何在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格式(獲取lat和long),但輸出為空。

如何獲得經久耐用的圖像?

如果還有其他獲取信息的方法,請幫助我

先感謝您

如果您已經擁有PHAsset,則無需執行其他任何操作(如您所說,您已經成功檢索了它們)。

你需要的是.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];

就是這樣,您在字典中獲得了經度和緯度。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM