1、添加引用Corelocation.framkwork
2、 .h文件添加 #import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController
{
CLLocationManager *locationManger;
}
3.m文件添加
locationManger =[[CLLocationManager alloc]init];
[locationManger setDelegate:self];
[locationManger setDistanceFilter:kCLDistanceFilterNone];
[locationManger setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManger startUpdatingLocation];
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"location:%@",newLocation);
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"error:%@",error);
}