CLLocation 定位

来源:互联网 发布:js获取子节点多一个 编辑:程序博客网 时间:2024/06/10 19:09
                                                                                 

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网络编程与云端应用》一书 

 

0 0
原创粉丝点击