16
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CLGeocoderを使って郵便番号を住所に変換する

Last updated at Posted at 2014-06-06
#import <CoreLocation/CoreLocation.h>

CLGeocoder *geocoder = [[CLGeocoder alloc] init];

[geocoder geocodeAddressString:@"100-0001" completionHandler:^(NSArray *placemarks, NSError *error) {
    CLPlacemark *placemark = placemarks.firstObject;

    NSString *prefectureString = placemark.administrativeArea;
    NSString *cityString       = placemark.locality;
    NSString *streetString     = placemark.subLocality;

    NSLog(@"Prefecture:%@", prefectureString);
    NSLog(@"City:%@", cityString);
    NSLog(@"Street:%@", streetString);
}];

正ジオコーディングは位置情報サービスの使用許可を求めるアラートが出ない。

郵便番号は以下のどの形式でもOK。

  • 100-0001
  • 1000001
  • 〒100-0001
  • 〒1000001

※追記
1000001
この形式だとうまく引っかからない場合があるので、頭にを付けておくと安全。

16
16
2

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
16
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?