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

自学Swift-斯坦福笔记整理(十四) Core Location and MapKit

2015-10-16 22:31 561 查看
Core Location

单纯的管理位置的信息

CLLocation基本对象

属性:coordinate,altitude,horizontal/verticalAccuracy,timestamp,speed,course

//维度 2D只为在地上没包含高度

var coordinate: CLLocationCoordinate2D

struct CLLocationCoordinate2D {

     CLLocationDegrees latitude

     CLLocationDegrees longitude

}

高度的变量为altitude

最高的精度叫做BestForNavigation

速度(speed)指的是瞬时速度

var speed: CLLocationSpeed

方向(course)

var course: CLLocationDirection

时间戳(Time stamp)

var timestamp: NSDate

class func authorizationStatus() -> CLAuthorizationStatus//authorized,Denied or Restricted

class func locationServicesEnabled() -> Bool//使用或不使用locations for app

class func significantLocationChangemonitoringAvailable() -> Bool

class func ismONITORINGavailableForClass(AnyClass!) -> Bool

class func isRangeingAvailable() -> Bool

func requestWhenInUseAuthorization()//只当APP启动的时候启用定位服务

func requestAlwaysAuthorization() //一直

要使用定位服务还需要在Info.plist中添加两个关键字中其中一个

NSLocationWhenInUseUsageDescription

NSLocationAlwaysUsageDescription

只需要有其中一个.不需要有固定的值..只需要有key在就可以

var desiredAccuracy: CLLocationAccuracy//精确

var distanceFilter: CLLocatoinDistance//移动距离后更新位置

func startUpdatingLocation()

func stoppedatingLocation()

MapKit

MKMapView 展示一个地图

大头针是一个协议..实现协议内有三个属性coordinate 坐标,经纬度

title 和subtitle 标题和子标题

大头针通过MKAnnotationView的子类来显示的MKPinAnnotationView

import MapKit

protocol MKAnnotation: NSObject{

     var coordinate: CLLocatoinCoordinate2D {get}

     var title: String! {get}

     var subtitle: String!{get}

}

标题不能为空,副标题可为空

var annotations: [MKAnnotation] {get}

func addAnnotation(MKSnnotatiON)

func addAnnotations([MKAnnotation])

func removeAnnotation(MKAnnotation)

func removaAnnotations([MKAnnotation])
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios swift uikit mapkit