由于是初学者,思绪可能较乱,敬请见谅!
1. 首先,将CoreLocation framework mapkit.framework框架导入到工程当中并且引用
2. 添加#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>引用头文件到你写的类文件中
3.创建一个CLLocation服务的管理者CLLocationManager,设置代理。定义为全局变量方便调用
@property (strong,nonatomic)CLLocationManager *locManager;
{
self.locationManager.delegate = self;
distanceFilter是距离过滤器,为了减少对定位装置的轮询次数,位置的改变不会每次都去通知委托,而是在移动了足够的距离时才通知委托程序
它的单位是米,这里设置为至少移动1000再通知委托处理更新;
1. 首先,将CoreLocation framework mapkit.framework框架导入到工程当中并且引用
2. 添加#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>引用头文件到你写的类文件中
3.创建一个CLLocation服务的管理者CLLocationManager,设置代理。定义为全局变量方便调用
@property (strong,nonatomic)CLLocationManager *locManager;
4.实例化位置管理器并设置代理,使用startUpdatingLocation和stopUpdatingLocation来开始和结束定位
{
[super viewDidLoad];
self.locationManager.delegate = self;
distanceFilter是距离过滤器,为了减少对定位装置的轮询次数,位置的改变不会每次都去通知委托,而是在移动了足够的距离时才通知委托程序
它的单位是米,这里设置为至少移动1000再通知委托处理更新;
self.locationManager.distanceFilter = 1000.0f; // 如果设为kCLDistanceFilterNone,则每秒更新一次;
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if (status == kCLAuthorizationStatusNotDetermined) {
// 如果授权状态还没有被决定就弹出提示框
} else if (status == kCLAuthorizationStatusDenied) {
// 如果授权状态