標籤:coco2d-x培訓 手遊開發培訓 中遊學院 天氣預報 ios項目
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.// BeiJing2.#define BJ_LATITUDE 40.063813.#define BJ_LONGITUDE 116.1346574.#define SH_LATITUDE 31.2194235.#define SH_LONGITUDE 121.4965586.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)