iOSCoreLocation.frameworkCoreLocationAPI
CLLocationManager CLLocationManagerdelegatedelegateCLLocationManager
CLLocation
CLHeading CLRegionCLCircularRegionCLBeaconRegion
CoreLocationCLLocationCoordinate2DCLLocationcoordinateCLLocationCoordinate2D CoreLocationAPIAPI
9.2.1
CoreLocation.framework3 CLLocationManager
CLLocationManagerdelegateCLLocationManagerDelegateCLLocationManagerDelegate CLLocationManagerstartUpdatingLocationstopUpdatingLocation
注意,,
,,为了在iOS应用中使用CoreLocation.framework需要完成两件事情①为应用添加CoreLocation.framework框架②在需要使用定位服务及相关类的源文件中使用“# import & lt; CoreLocation/CoreLocation.h>导入CoreLocation.framework的头文件。本章绝大部分示例都使用了CoreLocation.framework因此都需要执行上面两步操作。
CoreLocationCLLocationManagerdelegateCLLocationManagerdelegate CLLocationManager
+ locationServicesEnabled + deferredLocationUpdatesAvailable
+ significantLocationChangeMonitoringAvailable + headingAvailable
+ isRangingAvailableiOS 7
CLLocationManager
pausesLocationUpdatesAutomaticallyiOSYESiOSiOS distanceFilterCLLocationManager
desiredAccuracykCLLocationAccuracyBestForNavigationkCLLocationAccuracyBestkCLLocationAccuracy NearestTenMeters10kCLLocationAccuracyHundredMeterskCLLocationAccuracyKilometerkCLLocationAccuracyThreeKilometers activityTypeCLActivityTypeOtherCLActivityTypeAutomotiveNavigationCLActivityTypeFitnessCLActivityTypeOtherNavigation
CoreLocationiOS
ApplicationMain单一视图。storyboard5UIButton
5 longitudetxtlatitudetxtaltitudetxtspeedtxtcoursetxt5iboutlettouch InsidebnTapped:
编码/09/9.2 LocationTest/LocationTest/FKViewController。m
@ interface FKViewController () & lt; CLLocationManagerDelegate> @ property(强,原子)CLLocationManager * locationManager; @end @ implementation FKViewController - (void) viewDidLoad { (超级viewDidLoad);//创建CLLocationManager对象 自我。locationManager=[[CLLocationManager alloc] init); } ——(IBAction) bnTapped:发送者(id) {//如果定位服务可用 如果([CLLocationManager locationServicesEnabled]) { NSLog(@“开始执行定位服务”);//设置定位精度最佳精度 self.locationManager.desiredAccuracy=kCLLocationAccuracyBest;//设置距离过滤器为50米表示每移动50米更新一次位置 self.locationManager。distanceFilter=50;//将视图控制器自身设置为CLLocationManager的委托//因此该视图控制器需要实现CLLocationManagerDelegate协议 self.locationManager.delegate=自我;//开始监听定位信息 (自我。locationManager startUpdatingLocation]; } 其他的 { NSLog(@“无法使用定位服务”); } }//成功获取定位数据后将会激发该方法 - (void) locationManager: (CLLocationManager *)经理 NSArray didUpdateLocations:(*)的位置 {//获取最后一个定位数据 lastObject CLLocation *位置=[地点];//依次获取CLLocation中封装的经度,纬度,高度,速度,方向等信息 self.latitudeTxt。文本=[NSString stringWithFormat: @“% g”, location.coordinate.latitude]; self.longitudeTxt。文本=[NSString stringWithFormat: @“% g”, location.coordinate.longitude]; self.altitudeTxt。文本=[NSString stringWithFormat: @“% g”, location.altitude]; self.speedTxt。文本=[NSString stringWithFormat: @“% g”, location.speed]; self.courseTxt。文本=[NSString stringWithFormat: @“% g”, location.course]; }//定位失败时激发的方法 - (void) locationManager: (CLLocationManager *)经理 didFailWithError:(NSError *)错误 { NSLog(@“定位失败:% @”,错误); } @end
1 cllocationmanagercllocationmanagerdelegatecllocationmanagerstartupdatinglocation
CLLocationManagerdelegateCLLocationManagerDelegatedelegatelocationManager: didUpdateLocations: CLLocation
CLLocation
高度coordinateCLLocationCoordinate2D
course0°90°180°270°
horizontalAccuracy verticalAccuracyiOS
速度/时间戳
OKXcode
9.2.2iOS
iOSGPSiOS iOSiOSiOS9.2
9.2
城市自行车
城市运行高速公路开车
高速公路Driver9.3