您的位置:首页 > 移动开发 > IOS开发

ios系统地图的定位功能

2016-01-29 14:07 429 查看
#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:kCLLocation
4000
AccuracyBest];

//多远的距离会更新一次(位置更新是时时的,但是,每隔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
{

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios 地图