[英]How to get place where image from photo gallery was taken (not GPS coordinates) on iOS?
Images in Photos app on iOS sometimes have associated place where photo was taken. iOS上“照片”应用程序中的图像有时与拍摄照片的位置有关。 Eg, city name or even particular place in the city like Pike Place Market in Seattle.
例如,城市名称,甚至是城市中的特定地点,例如西雅图的派克市场。 This place is displayed as image title in nav bar in iOS Photos app.
此地点在iOS相册应用的导航栏中显示为图像标题。
How can I get that metadata? 如何获得该元数据?
I'm accessing photos using PHAssetCollection.FetchAssetCollections
method. 我正在使用
PHAssetCollection.FetchAssetCollections
方法访问照片。
You can get location directly from PHAsset
Object. 您可以直接从
PHAsset
对象获取位置。 To get place Info. 获取地点信息。 ie Address use
CoreLocation
Framework 即地址使用
CoreLocation
框架
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)")
}
}
}
For the address you can get address directly from CLPlacemark
Object 对于地址,您可以直接从
CLPlacemark
对象获取地址
See the reference : https://developer.apple.com/documentation/corelocation/clplacemark 请参阅参考资料: https : //developer.apple.com/documentation/corelocation/clplacemark
from previous code let firstPlacemark = placemarks.first
从之前的代码中,
let firstPlacemark = placemarks.first
firstPlacemark.property
(property mention below) firstPlacemark.property
( 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.