zoukankan      html  css  js  c++  java
  • 定位

    #import "ViewController.h"

    #import <CoreLocation/CoreLocation.h>

    @interface ViewController ()<CLLocationManagerDelegate>

     /**  定位管理者对象 ***/

    @property (nonatomic, strong) CLLocationManager *mgr;

    @property (nonatomic, strong) CLCircularRegion *region;

    @end

    @implementation ViewController

    - (CLLocationManager *)mgr{

        if (!_mgr) {

            _mgr = [[CLLocationManager alloc] init];

        }

        return _mgr;

    }

    - (void)viewDidLoad {

        [super viewDidLoad];

        //1. 设置代理

        self.mgr.delegate = self;

        

        

        

        // 3. 开始监听用户所在区域

        // CLRegion 有两个子类, 用来指定区域

        // 指定蓝牙范围: CLBeaconRegion

        // 指定圆形范围: CLCircularRegion

        // 创建中心点

        CLLocationCoordinate2D center = CLLocationCoordinate2DMake(39.915094,116.487775);

        // 创建圆形区域, 指定中心点 经纬度以及半径

        self.region = [[CLCircularRegion alloc] initWithCenter:center radius:1000 identifier:@"大望路"];

        

        // [注意] 如果是ios8 必须主动请求用户 授权

        if(IOS8){

            [self.mgr requestAlwaysAuthorization];

        }else{

            [self.mgr startMonitoringForRegion:self.region];

        }

        

        

    }

    - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status

    {

        if (status == kCLAuthorizationStatusNotDetermined) {

            LogGreen(@"正在授权");

        }else if ((status == kCLAuthorizationStatusAuthorizedAlways) || (status == kCLAuthorizationStatusAuthorizedWhenInUse)){

            [self.mgr startMonitoringForRegion:self.region];

        }else{

        

            LogGreen(@"授权失败");

        }

    }

    #pragma mark - CLLocationManagerDelegate

    /**

     *  进入某个监听区域 开始调用

     */

    - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region

    {

        LogRed(@"  进入某个监听区域 开始调用");

    }

    /**

     *  离开监听区域开始调用

     */

    - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region

    {

        LogRed(@"   超出某个监听区域 开始调用");

    }

  • 相关阅读:
    网络集群
    数组集合删除算法
    数组集合添加算法
    网络编程的认识
    NFC and Contactless Technologies
    斐波那契数列-有一对兔子
    Android历史版本
    最大公约数及最小公倍数是个什么东西
    要知其然还要知其所以然printChar
    Android项目Library导入的问题整理
  • 原文地址:https://www.cnblogs.com/guangleijia/p/4826609.html
Copyright © 2011-2022 走看看