1 . 在项目里加入� CoreLocation.framework
2 .在 .h 文件输入例如以下:
1.#import <CoreLocation/CLLocation.h>
2.#import <CoreLocation/CLLocationManager.h>
3.#import <coreLocation/CLGeocoder.h>
4.#import <coreLocation/CLPlacemark.h>
3 . 在 .m文件输入例如以下:
1.// BeiJing
2.#define BJ_LATITUDE 40.06381
3.#define BJ_LONGITUDE 116.134657
4.#define SH_LATITUDE 31.219423
5.#define SH_LONGITUDE 121.496558
6.
7....
8. CLLocation *loc = [[CLLocation alloc]initWithLatitude:BJ_LATITUDE longitude:BJ_LONGITUDE];
9.
10. CLGeocoder *geocoder = [[CLGeocoder alloc] init];
11. [geocoder reverseGeocodeLocation:loc completionHandler:^(NSArray *array, NSError *error) {
12.
13. if (array.count > 0) {
14.
15. CLPlacemark *placemark = [array objectAtIndex:0];
16.
17. NSString *city = placemark.administrativeArea;
18. NSLog(@"位于:%@",city);
19. NSLog(@"%@",placemark);
20. }
21. }];
4 . 结果:
1.2014-03-19 19:52:01.320 location[1366:70b] 位于:北京市
2.location[1366:70b] 中国北京市海淀区苏家坨镇, 中国北京市海淀区苏家坨镇 @ <+0.00000000,+0.00000000> +/- 100.00m, region CLCircularRegion (identifier:'<+40.02953100,+116.20858200> radius 9051.17', center:<+40.02953100,+116.20858200>, radius:9051.17m)