ios項目開發(天氣預報項目):通過經緯度擷取當前城市名稱

來源:互聯網
上載者:User

標籤: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)



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.