How do I get the name of City, Province, State from PHAsset in iOS 8 Photos Framework?

Is it possible to access location information such as city name and state from PHAsset. The iOS Photos app shows very specific location information like Belltown, Seattle, Washington, USA. However, all I was able to get from PHAsset was the CALocation from the location property. Which, I suppose, only gives me the geocoords and therefore still requires reverse geocoding. I have thousands of photos to change geocoding per user. So I would like to avoid having to do reverse geocoding and simply access human-readable information that Apple already displays in the Photos app.

Long story short, given a PHAsset object, how do I access the city name for the location of the photo, without using a reverse geocoding service?

+3


source to share


2 answers


There PHAsset

is a property for location, use it.

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

      

...



CLGeocoder *geocoder = [CLGeocoder new];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
    CLPlacemark *placemark = [placemarks lastObject];
    self.cityString = placemark.addressDictionary[kCityString];
    // or equivalent
    self.cityString = placemark.locality;
}];

      

go and browse CLPlacemark

for other properties.

+1


source


You can use the Google Maps API to perform geocoding translations in latitude and longitude. See here for more details:

https://developers.google.com/maps/documentation/geocoding/#ReverseGeocoding.



Then you can cache the results and reuse them if you are requesting locations that are very close. Using a GeoLite geodatabase is another matter, but that's about 100 megabytes.

See here for download

0


source







All Articles