CLLocation 定位

                                                                                 

CLLocationManager *manager = [[CLLocationManager alloc]init];

manager.delegate = self;

manager.desiredAccuarcy = KCLLocationAccuracyBest;

manager.distanceFilter = 100.0f;


注释:desiredACCuarcy 是定位的精准度,有以下几个属性:KCLLocationAccuracyNearestTenMeters 表示精准度到10米

                                                                                                  KCLLocationAccuracyNearestHundred   表示精准度到100米

                                                                                                  KCLLocationAccuracyNearestkilometer    表示精准度到1000米

                                                                                                  KCLLocationAccuracyNearestThreeKilome  表示精准度到3000米

                                                                                                  KCLLocationAccuracyNearestBest    表示设备使用电池供电时可达到的最大精度

                                                                                                  KCLLocationAccuracyNearestBestForNavigation  导航时的最高精度,一般需要外接电源才可使用

distanceFilter 设备多少距离之后开始更新位置信息,单位是米


[manager startUpdatingLocation]  // 开始测位

[manager stopUpdatingLocation]  //结束测位

   [manager allowDeferredLocationUpdatesUntilTraveled:(CLLocationDistance) timeout:(NSTimeInterval)]  //设置延迟更新,使应用在后头不更新位置

[manager disallowDeferredLocationUpdates]  //关闭延迟更新

 [manager pausesLocationUpdatesAutomatically]  //将定位服务的开启和暂停交个系统


当用户的设备达到过滤距离的时候会调用:-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations //取得位置更新信息

和-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error  //未取得位置信息


取得经纬度方法: CLLocation *m_location = [locations lastObject];
    textfield.text = [NSString stringWithFormat:@"%3.5f",m_location.coordinate.longitude ];  //纬度
    textfield1.text = [NSString stringWithFormat:@"%3.5f",m_location.coordinate.latitude];   //经度
    textfield2.text = [NSString stringWithFormat:@"%3.5f",m_location.altitude];                    //高度

                                                                                                                       
                                                                                                                                                        ps:  参考《ios网络编程与云端应用》一书 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值