//
//ViewController.m
//A01_獲取當(dāng)前位置(定位)
//
//Created by apple on 15/6/27.
//Copyright (c) 2015年itcast. All rights reserved.
//
#import"ViewController.h"
#import
@interfaceViewController()
@property(nonatomic,strong)CLLocationManager* manager;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{
//獲取當(dāng)前的位置,使用CLLocationManager對象
CLLocationManager*manager = [[CLLocationManageralloc]init];
//當(dāng)要使用的時(shí)候,請求授權(quán)
#warning requestWhenInUseAuthorization的方法畏纲,只能在8.0以上系統(tǒng)調(diào)用
if([[UIDevicecurrentDevice].systemVersiondoubleValue] >=8.0) {
[managerrequestWhenInUseAuthorization];
}
////不管三七二十一,直接請求授權(quán)
//[manager requestAlwaysAuthorization];
//設(shè)置代理
manager.delegate=self;
//每一百米定位一次-內(nèi)部還是時(shí)時(shí)定位迈窟,只是過一百米后,調(diào)用代理方法
manager.distanceFilter=100;
//定位的時(shí)候忌栅,設(shè)置誤差精確度在10米范圍內(nèi),精確度越高车酣,比較耗性能
manager.desiredAccuracy=10;
//開啟定位(時(shí)時(shí)定位)
[managerstartUpdatingLocation];
self.manager= manager;
}
#pragma mark獲取定位位置信息
-(void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray*)locations{
//CLLocation位置對象
for(CLLocation*locinlocations) {
NSLog(@"當(dāng)前位置的經(jīng)緯度經(jīng)度:%lf緯度:%lf行走速度%lf",loc.coordinate.longitude,loc.coordinate.latitude,loc.speed);
}
//一旦定位到信息,馬上停止定位
//[manager stopUpdatingLocation];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end