要取得位置,就需要使用GPS,iOS5 以上的版本當使用 startUpdatingLocation
時會自動詢問是否開啟GPS唷。
(1)增加CoreLocation.framework
(2)在ViewController 內加入
#import <CoreLocation/CoreLocation.h>
(3) 加入init 的location manager related code.
//Init location manager
CLLocationManager* locationManager = [ [ CLLocationManager alloc] init];
locationManager.delegate = self; //we must implement the protocol
//Choose your accuracy level
//To turn on gps (if it isn't on already)
[locationManager startUpdatingLocation];
//To turn gps off (if no other apps are listening)
[locationManager stopUpdatingLocation];
留言列表