gpt4 book ai didi

ios - 如何在 iOS 上获取照片库中的图像拍摄位置(不是 GPS 坐标)?

转载 作者:行者123 更新时间:2023-11-28 23:58:01 24 4
gpt4 key购买 nike

iOS 上的“照片”应用中的图像有时与拍摄照片的地点相关联。例如,城市名称,甚至是城市中的特定地点,例如西雅图的派克市场。此地点在 iOS 照片应用程序的导航栏中显示为图像标题。

如何获取该元数据?

我正在使用 PHAssetCollection.FetchAssetCollections 方法访问照片。

最佳答案

您可以直接从 PHAsset 对象获取位置。获取地点信息。即地址使用 CoreLocation Framework

func reverseGeoCoding(asset: PHAsset) {
let location = asset.location

let geocoder = CLGeocoder()
geocoder.reverseGeocodeLocation(location) { (placemarks, error) in

if let error = error {
print("Geo Coding Error: \(error.localizedDescription)")
return
}

guard let placemarks = placemarks,
let firstPlacemark = placemarks.first,
let addressDictionary = firstPlacemark.addressDictionary else { return }
// let street = addressDictionary["Street"]
// let city = addressDictionary["City"]
// let state = addressDictionary["State"]
// let zip = addressDictionary["ZIP"]
print(addressDictionary.description)
if let array = addressDictionary["FormattedAddressLines"] as? [Any] {
let address = array.map { "\($0)" }.joined(separator: ",\n")
print("Address : \(address)")
}
}
}

更新:

地址可以直接从CLPlacemark对象中获取地址

参见引用资料:https://developer.apple.com/documentation/corelocation/clplacemark

从前面的代码let firstPlacemark = placemarks.first

firstPlacemark.property(下面提到的属性)

// CLPlacemark properties

open var name: String? { get } // eg. Apple Inc.

open var thoroughfare: String? { get } // street name, eg. Infinite Loop

open var subThoroughfare: String? { get } // eg. 1

open var locality: String? { get } // city, eg. Cupertino

open var subLocality: String? { get } // neighborhood, common name, eg. Mission District

open var administrativeArea: String? { get } // state, eg. CA

open var subAdministrativeArea: String? { get } // county, eg. Santa Clara

open var postalCode: String? { get } // zip code, eg. 95014

open var isoCountryCode: String? { get } // eg. US

open var country: String? { get } // eg. United States

open var inlandWater: String? { get } // eg. Lake Tahoe

open var ocean: String? { get } // eg. Pacific Ocean

open var areasOfInterest: [String]? { get } // eg. Golden Gate Park

关于ios - 如何在 iOS 上获取照片库中的图像拍摄位置(不是 GPS 坐标)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50549030/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com