LoginSignup
18
19

More than 5 years have passed since last update.

写真の位置情報から住所を調べる

Last updated at Posted at 2012-05-25

iOS5のCLGeocoderを使うと、写真等に含まれる位置情報から、住所や郵便番号、国名などを調べることができます。CoreLocation.frameworkが必要。


// ALAssetから位置情報を取得
CLLocation *location = [asset valueForProperty:ALAssetPropertyLocation];

// 逆ジオコーディング
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:location
               completionHandler:^(NSArray *placemarks, NSError *error){

                   CLPlacemark *place = [placemarks lastObject];
                   // 情報表示
                   NSLog(@"%@,%@\n",place.locality,place.country);
               }];

CLGeocoderのreverseGeocodeLocation:completionHandler:メソッドに位置情報(CLLocation)を渡し、結果をblocksで受け取ります。

フォトライブラリからALAssetを取り出すコードは省略しています。「iOS4プログラミングブック」などで詳しく解説されています。

取得できる情報の詳細は CLPlacemark Class Reference にあります。
http://developer.apple.com/library/ios/#DOCUMENTATION/CoreLocation/Reference/CLPlacemark_class/Reference/Reference.html#//apple_ref/occ/cl/CLPlacemark

18
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
19