美文网首页
iOS开发-地图02-指南针

iOS开发-地图02-指南针

作者: MonkeyHeng | 来源:发表于2016-02-10 17:36 被阅读279次
#import "ViewController.h"  
#import <CoreLocation/CoreLocation.h>  
  
@interface ViewController ()<CLLocationManagerDelegate>  
  
@property (nonatomic, strong) CLLocationManager *manager;  
@property (nonatomic, strong) UIImageView *imageView;  
  
@end  
  
@implementation ViewController  
  
- (void)viewDidLoad {  
    [super viewDidLoad];  
    // Do any additional setup after loading the view, typically from a nib.  
      
    self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_imageView"]];  
    self.imageView.center = self.view.center;  
    [self.view addSubview:self.imageView];  
      
    // 指南针需要在设备上才可以测试 在模拟器无法测试  
    self.manager.delegate = self;  
    // 获取方向不需要授权  
    [self.manager startUpdatingHeading];  
      
    // 区域检测需要位置所以对于iOS8需要请求权限  
    [self.manager requestAlwaysAuthorization];  
      
      
    // 121.551331,38.889706  
    CLLocationCoordinate2D center = CLLocationCoordinate2DMake(38.889706, 121.551331);  
    CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:center radius:500 identifier:@"数码广场"];  
      
    [self.manager startMonitoringForRegion:region];  
      
}  
  
/** 
 *  进入区域 
 * 
 *  @param manager 触发事件的对象 
 *  @param region  进入哪个区域 
 */  
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {  
    NSLog(@"进入 %@", region.identifier);  
}  
  
/** 
 *  退出区域 
 * 
 *  @param manager 触发事件的对象 
 *  @param region  退出哪个区域 
 */  
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {  
    NSLog(@"退出 %@", region.identifier);  
}  
  
/** 
 *  获取用户的方向 
 * 
 *  @param manager    触发事件的对象 
 *  @param newHeading 获取到的方向信息 
 */  
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {  
//    获取到的为与磁北或者真北的夹角  
//    获取到的磁北的角度 magneticHeading  
//    获取到的真北的角度 trueHeading  
    NSLog(@"%.f", newHeading.magneticHeading);  
    [manager stopUpdatingHeading];  
}  
  
- (CLLocationManager *)manager {  
    if (_manager == nil) {  
        _manager = [[CLLocationManager alloc] init];  
    }  
    return _manager;  
}  
  
- (void)didReceiveMemoryWarning {  
    [super didReceiveMemoryWarning];  
    // Dispose of any resources that can be recreated.  
}  
  
@end 

相关文章

  • iOS开发-地图02-指南针

  • iOS 高德地图开发详解

    iOS 高德地图开发详解

  • 地图与定位

    OCiOS开发:地图与定位 - 李鴻耀 - 博客频道 - CSDN.NET iOS开发之地图-定位/...

  • 指南针和地图

    指南针和地图相比,指南针只知道大概的方向,而地图有很详细的位置等信息。 但地图是事先绘制好的,就算现在的高德地图、...

  • iOS 地图

    iOS 地图 基础 一 :定位 在 iOS 程序开发中 地图功能是普遍存在的,刚好最近都在研究地图的功能。总结一下...

  • 读《爆裂》,触摸未来社会生存法则(二)

    今天分享的是指南针优于地图、风险优于安全、违抗优于服从共三个原则。 03 指南针优于地图 地图意味着掌握详细的地形...

  • iOS开发 - 指南针

  • iOS开发之地图

    在iOS开发中,地图也是很多App都需要使用的功能。本文主要对iOS中的地图知识点进行介绍。需要说明的是地图看似很...

  • iOS 高德地图 自定义地图样式

    iOS 高德地图 自定义地图样式 1.创建高德地图账号,创建应用高德地图开放平台的开发者在取得开发者账号后,可以进...

  • 地图

    在iOS开发中,要想加入地图的地位这两大功能,必须基于两个框架进行开发:Map Kit(用于地图展示)、Core ...

网友评论

      本文标题:iOS开发-地图02-指南针

      本文链接:https://www.haomeiwen.com/subject/yltukttx.html