ios系統地圖的定位功能
阿新 • • 發佈:2019-01-03
#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];
//多遠的距離會更新一次(位置更新是時時的,但是,每隔10米才會在地圖上更新一次)
[_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
{
}