#import "LocationViewController.h"
#import <CoreLocation/CoreLocation.h>
@interface LocationViewController ()<CLLocationManagerDelegate>
{
CLLocationManager * _locationManager ;
}
@end
@implementation LocationViewController
- (void)viewDidLoad
{
[super viewDidLoad];
_locationManager = [[CLLocationManager alloc] init];
if ([CLLocationManager locationServicesEnabled] == NO)
{
NSLog(@"定位服务暂不可用");
return;
}
[_locationManager setDistanceFilter:kCLLocationAccuracyBest];
[_locationManager setDesiredAccuracy:.1];
[_locationManager setDelegate:self];
[_locationManager startUpdatingLocation];
[_locationManager startUpdatingHeading];
}
#pragma mark 更新的时候 会调用这个方法
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation * location = [locations lastObject];
CLLocationDistance hight = location.altitude;
NSLog(@"当前用户的海拔高度为 ==%f",hight);
CLLocationCoordinate2D coor = location.coordinate;
NSLog(@"纬度===%f,经度===%f",coor.latitude,coor.longitude);
[_locationManager stopUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
}