zoukankan      html  css  js  c++  java
  • IOS GPS跟踪备注

    CLLocationManager还提供了如下类方法来判断当前设备的定位相关服务状态。

    Ø + locationServicesEnabled:返回当前定位服务是否可用。

    Ø + deferredLocationUpdatesAvailable:返回延迟定位更新是否可用。

    Ø + significantLocationChangeMonitoringAvailable:返回重大位置改变监听是否可用。

    Ø + headingAvailable:返回该设备是否支持磁力计计算方向。

    Ø + isRangingAvailable:返回蓝牙信号范围服务是否可用。这是iOS 7新增的方法。

    除此之外,在使用CLLocationManager开始定位之前,还可为该对象设置如下属性。

    Ø pausesLocationUpdatesAutomatically:设置iOS设备是否可暂停定位来节省电池的电量。如果该属性设为“YES”,则当iOS设备不再需要定位数据时,iOS设备可以自动暂停定位。

    Ø distanceFilter:设置CLLocationManager的自动过滤距离。也就是说,只有当设备在水平方向的位置改变超过该数值(以米为单位)指定的距离时才会生成一次位置改变的信号。

    Ø desiredAccuracy:设置定位服务的精度。该属性值支持kCLLocationAccuracyBestForNavigation(导航级的最佳精确度)、kCLLocationAccuracyBest(最佳精确度)、kCLLocationAccuracy NearestTenMeters(10米误差)、kCLLocationAccuracyHundredMeters(百米误差)、kCLLocationAccuracyKilometer(千米误差)、kCLLocationAccuracyThreeKilometers(三千米误差)等常量值。当然,也可直接指定一个浮点数作为定位服务允许的误差。

    Ø activityType:设置定位数据的用途。该属性支持CLActivityTypeOther(定位数据作为普通用途)、CLActivityTypeAutomotiveNavigation(定位数据作为车辆导航使用)、CLActivityTypeFitness(定位数据作为步行导航使用)和CLActivityTypeOtherNavigation(定位数据作为其他导航使用)这几个枚举值之一。

    ------------CLLocation
    CLLocation类代表一个位置信息,其中还包括了方向和速度。比如我在长安街188号以5公里/小时的速度往西走。CLLocation具有下面的属性和方法:
    @property  CLLocationCoordinate2D coordinate; //以经度和纬度表示的位置信息
    @property CLLocationDistance altitude;  //海拔
    @property CLLocationAccuracy horizontalAccuracy; //水平精度(如:精确到米)
    @property CLLocationAccuracy verticalAccuracy; //垂直精度
    @property CLLocationDirection course; //方向
    @property CLLocationSpeed speed; //速度
    -(NSDate *)timeStamp;
    //两个位置之间的距离
    -(CLLocationDistance)distanceFromLocation:(CLLocation *)location;


    -------------CLLocationManager
    CLLocationManager类管理和提供位置服务。它的属性和方法有:
    @property CLLocation *location; //位置
    @property id<CLLocationManagerDelegate> delegate;
    @property CLLocationDistance distanceFilter; //距离过滤,比如:500以内
    @property CLlocationAccuracy verticalAccuracy; //垂直精度
    -(void) startUpdatingLocation; //开始更新位置(比如:你在往某个地方走)
    -(void)stopUpdatingLocation; //停止更新位置
    -(void)startUpdatingHeading; //开始更新方向(比如:你改往东走)
    -(void)stopUpdatingHeading; //停止更新方向
    CLLocationManagerDelegate是一个委托类。你的应用程序需要使用这个委托类。当用户改变位置的时候,CLLocationManager回调的方法是:
    -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation;
    当用户改变方向的时候,所调用的方法是:
    -(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLLHeading *)newHeading;
    当iPhone无法获得当前位置的信息时,所回调的方法是:
    -(void)locationManager: (CLLocationManager *)manager didFailLoadWithError:(NSError *)error;


    =========================================================================
    下面我们来看一个位置类的基本步骤:
    一、启动定位服务
    CLLocationManager *locManager = [[CLLocationManager alloc] init];
    locManager.delegate = self;
    [locManager startUpdatingLocation];
    二、获得位置信息
    -(void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation fromLocation: (CLLocation *)oldLocation
    {
    NSTimeInterval howRecent = [newLocation.timestamp timeIntervalSinceNow];
    if(howRecent < -10) return ; //离上次更新的时间少于10秒
    if(newLocation.horizontalAccuracy > 100) return; //精度> 100米
    //经度和纬度
    double lat = newLocation.coordinate.latitude;
    double lon = newLocation.coordinate.longitude;
    }
    三、获得方向信息(比如往南走)
    -(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
    {
    //获得方向
    CLLocationDirection heading = newHeading .trueHeading;
    }
    四、停止定位
    [locManager stopUpdatingLocation];
    你可以设置你想要的精度和距离过滤:
    locManager.desiredAccuracy = kLLocationAccuracyBest;
    locManager.distanceFilter = 1000;

  • 相关阅读:
    使用Visual Studio给SharePoint列表添加Event Receiver
    使用客户端对象模型回写SharePoint列表
    思考:通过源码进行安装的前提是什么
    思考:学习一门语言真的是仅仅只有为了使用吗?或者说学习一个语言如果在工作中不使用,那么学习它还有什么好处和价值呢?
    思考:(使用下载工具比如yum,maven等)下载(库或者jar)到本地都需要设置源
    思考:代码块的大小是进行代码抽出一个方法或者进行重构或者是否在设计时设计为一个方法的衡量因素之一吗?
    思考:对源的包装是为了更好的隔离和在中间插入一些层?
    Spring Cloud和Spring Boot的认识
    如何对待基础知识:
    为什么总觉得事情应付不过来,总觉得事情需要花费很多时间?
  • 原文地址:https://www.cnblogs.com/shikyoh/p/4243596.html
Copyright © 2011-2022 走看看