MapKit - CLLocationManager

大概简介

设备的朝向方向枚举

/*
* CLDeviceOrientation
* Discussion:
* Specifies a physical device orientation,equivalent to UIDeviceOrientation.
*/
public enum CLDeviceOrientation : Int32 {

case unknown

case portrait

case portraitUpsideDown

case landscapeLeft

case landscapeRight

case faceUp

case faceDown

}

获取当前用户的权限设置

/*
* CLAuthorizationStatus
* Discussion:
* Represents the current authorization state of the application.
*/

public enum CLAuthorizationStatus : Int32 {

// User has not yet made a choice with regards to this application

case notDetermined 还没决定

// This application is not authorized to use location services.Due

// to active restrictions on location services,the user cannot change

// this status,and may not have personally denied authorization

case restricted 没有授权

// User has explicitly denied authorization for this application,or

// location services are disabled in Settings.

case denied 已经明确不授权,或者设置里面压根就不存在这个

// User has granted authorization to use their location at any time,

// including monitoring for regions,visits,or significant location changes.

//

// This value should be used on iOS,tvOS and watchOS.It is available on

// MacOS,but kCLAuthorizationStatusAuthorized is synonymous and preferred.

@available(iOS 8.0,*)

case authorizedAlways 总是有权限

// User has granted authorization to use their location only when your app

// is visible to them(it will be made visible to them if you continue to

// receive location updates while in the background).Authorization to use

// launch APIs has not been granted.

//

// This value is not available on MacOS.It should be used on iOS,tvOS and

// watchOS.

@available(iOS 8.0,*)

case authorizedWhenInUse app 使用时候有权限

// User has authorized this application to use location services.

//

// This value is deprecated or prohibited on iOS,tvOS and watchOS.

// It should be used on MacOS.

@available(iOS,introduced: 2.0,deprecated: 8.0,message: "Use kCLAuthorizationStatusAuthorizedAlways")

public static var authorized: CLAuthorizationStatus { get }  iOS 8之后已废弃

}

关于这个类

检查app是否能启动定位服务
locationServicesEnabled()-> Bool

指南针能不能用
headingAvailable()-> Bool

位置发生改变能否监控
significantLocationChangeMonitoringAvailable()-> Bool

某个地区类的改变能否检测到
isMonitoringAvailable(for regionClass: Swift.AnyClass)-> Bool

能否测距
isRangingAvailable()-> Bool

获取当前权限状态
authorizationStatus()-> CLAuthorizationStatus

代理
delegate

对象

设置一个更新定位的距离间距值,如果是kCLDistanceFilterNone的话,用户所有行动都会更新定位
distanceFilter: CLLocationDistance(Double)

定位精度
desiredAccuracy: CLLocationAccuracy

CLLocationAccuracy 对应的枚举 {

public let kCLLocationAccuracyBestForNavigation: CLLocationAccuracy

public let kCLLocationAccuracyBest: CLLocationAccuracy

public let kCLLocationAccuracyNearestTenMeters: CLLocationAccuracy

public let kCLLocationAccuracyHundredMeters: CLLocationAccuracy

public let kCLLocationAccuracyKilometer: CLLocationAccuracy

public let kCLLocationAccuracyThreeKilometers: CLLocationAccuracy

}

自动暂停定位更新
pausesLocationUpdatesAutomatically: Bool

允许后台更新定位,需要设置UIBackgroundModes在Info.plist
allowsBackgroundLocationUpdates: Bool9.0之后支持

showsBackgroundLocationIndicator: Bool 11.0

最新的定位信息
location: CLLocation? { get }

导航过滤器,定义多少角度的改变再去更新,默认是1 degree
headingFilter

只有设备在正常方向才会正确导航(CLDeviceOrientationPortrait is used.其他都ignored)
headingOrientation: CLDeviceOrientation

获取最后的导航方向
heading: CLHeading? { get }

最大的地区监控距离(距离中心点,任何大于此值的区域都会返回kCLErrorRegionMonitoringFailure)
maximumRegionMonitoringDistance: CLLocationDistance { get }

检索当前正在监视的区域的一组对象。如果之前有任何location manager也监控过的话,会将之前的值也添加到这个set里面。
monitoredRegions: Set { get }

检索一组表示该位置管理器主动提供范围的区域的对象
rangedRegions: Set { get }

方法

requestWhenInUseAuthorization()

requestAlwaysAuthorization()

startUpdatingLocation()

stopUpdatingLocation()

requestLocation()

startUpdatingHeading()

stopUpdatingHeading()

立即关闭校准
dismissHeadingCalibrationDisplay()

开启/关闭检测重要位置变化,通过位置变化代理方法进行回调
startMonitoringSignificantLocationChanges()
stopMonitoringSignificantLocationChanges()

1.异步停止监测指定区域,不会及时反馈在monitoredRegions里面
stopMonitoring(for region: CLRegion)
2.之前有注册过得相同标识符的区域,会被移除。相对于非环形和更大的区域,这个方法会优先监控环形的区域和更小的区域。也是异步完成的。不会及时反馈在monitoredRegions里面
startMonitoring(for region: CLRegion)

异步取回特定区域的cache状态,state通过代理方法locationManager:didDetermineState:forRegion:取得
requestState(for region: CLRegion)

开始/结束计算指定区域中信标的范围
startRangingBeacons(in region: CLBeaconRegion)
stopRangingBeacons(in region: CLBeaconRegion)

允许后台以低功耗状态延迟更新位置信息
1.allowDeferredLocationUpdates(untilTraveled distance: CLLocationDistance,timeout: TimeInterval)
2.disallowDeferredLocationUpdates()
3.eferredLocationUpdatesAvailable() -> Bool

你可能感兴趣的:(MapKit - CLLocationManager)