gpt4 book ai didi

ios - 如何从 iOS 8 照片框架中的 PHAsset 获取城市名称、省、州?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:16:41 24 4
gpt4 key购买 nike

是否可以从 PHAsset 访问城市名称和州等位置信息。 iOS 照片应用程序显示非常具体的位置信息,例如美国华盛顿州西雅图的贝尔敦。但是,我能够从 PHAsset 访问的所有内容都是来自 location 属性的 CALocation。我相信这只会为我提供地理坐标,因此仍然需要反向地理编码。我有数千张照片可以对每个用户进行反向地理编码。因此,我想避免进行反向地理编码,而只是访问 Apple 已经在照片应用程序中显示的人类可读位置信息。

简而言之,给定一个 PHAsset 对象,我如何在不使用反向地理编码服务的情况下访问照片位置的城市名称?

最佳答案

PHAsset 中有一个位置属性,使用它。

static NSString *const kCityString  = @"City";
@property (nonatomic, copy) NSString *cityString;

...

CLGeocoder *geocoder = [CLGeocoder new];
__weak typeof(self) weakSelf = self;

[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
__strong typeof(weakSelf) strongSelf = weakSelf;

CLPlacemark *placemark = placemarks.lastObject;

// deprecated since iOS 11.0
strongSelf.cityString = placemark.addressDictionary[kCityString];

// or equivalent
strongSelf.cityString = placemark.locality;
}];

去看看 CLPlacemark 的其他属性。

关于ios - 如何从 iOS 8 照片框架中的 PHAsset 获取城市名称、省、州?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27444093/

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