1 . 在項目裡添加 CoreLocation.framework
2 .在 .h 文件輸入如下:
1.#import2.#import 3.#import 4.#import
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)