- (CLLocationManager *)locationManager
{
if (!_locationManager) {
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.distanceFilter = ;
[_locationManager requestAlwaysAuthorization];//添加这句
}
return _locationManager;
} #pragma mark - CLLocationManagerDelegate - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
debugMethod();
CLLocation *currentLocation = [locations lastObject];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks firstObject]; }]; //关闭定位服务
[self.locationManager stopUpdatingLocation];
} #pragma mark - IBAction //定位按钮被点中
- (IBAction)locationBtnDidClick:(id)sender {
debugMethod();
if([CLLocationManager locationServicesEnabled]) {
[self.locationManager startUpdatingLocation];
} else {
[self.tableView makeToast:@"请打开定位服务" duration:1.0 position:@"center"];
}
} info.plist中加入两行:
NSLocationAlwaysUsageDescription : 点击"允许"以开启云买手定位服务
NSLocationWhenInUseDescription : 点击"允许"以开启云买手定位服务

CoreLoation的更多相关文章

  1. ReactiveCocoa Tutorial

    ReactiveCocoa Tutorial – The Definitive Introduction: Part 1/2 ReactiveCocoa教程——明确的介绍:第一部分(共两部分) As ...

  2. 获取图片的metaData

    获取图片的metaData 获取简易的metaData较为容易,以下是测试图: 以下是本人提供的源码: UIImage+MetaData.h // // UIImage+MetaData.h // P ...

随机推荐

  1. Bootstrap系列 -- 20. 禁用状态

    Bootstrap框架的表单控件的禁用状态和普通的表单禁用状态实现方法是一样的,在相应的表单控件上添加属性“disabled” 在使用了“form-control”的表单控件中,样式设置了禁用表单背景 ...

  2. 4G时代的抢钱之道

    最近最大的事件恐怕就是移动的4G上线了,50元600M起计价,上网速度最高理论到达100Mbps,相当于一秒下载10MB的数据,或者是一分钟下载一张VCD(600M)电影. 当然,对于这样的流量套餐, ...

  3. 每天一个linux命令(37):free 命令

    free命令可以显示Linux系统中空闲的.已用的物理内存及swap内存,及被内核使用的buffer.在Linux系统监控的工具中,free命令是最经常使用的命令之一. 1.命令格式: free [参 ...

  4. 详解js中的闭包

    前言 在js中,闭包是一个很重要又相当不容易完全理解的要点,网上关于讲解闭包的文章非常多,但是并不是非常容易读懂,在这里以<javascript高级程序设计>里面的理论为基础.用拆分的方式 ...

  5. Git学习笔记——一个NB的分布式版本控制系统

    1. 命令: git init           创建新仓库 (在一个空文件下然后执行命令) git clone  + 路径      检出仓库,从本地或从服务器上 git status     查 ...

  6. .net架构设计读书笔记--第三章 第8节 域模型简介(Introducing Domain Model)

    一.数据--行为转变     很长的时间,典型的分析方法或多或少是以下两种,第一,收集需求并做一些分析,找出有关实体 (例如,客户. 订单. 产品) 和进程来实现. 第二,手持这种理解你尝试推断一个物 ...

  7. Java设计模式-装饰模式(Decorator)

    顾名思义,装饰模式就是给一个对象增加一些新的功能,而且是动态的,要求装饰对象和被装饰对象实现同一个接口,装饰对象持有被装饰对象的实例,关系图如下: Source类是被装饰类,Decorator类是一个 ...

  8. 详解Java中ArrayList、Vector、LinkedList三者的异同点

    转载:https://my.oschina.net/zzw922cn/blog/491631 一.ArrayList ArrayList是一个可以处理变长数组的类型,这里不局限于"数&quo ...

  9. 【HDU 5578】Friendship of Frog

    题 题意 求相同字母最近距离 分析 用数组保存各个字母最后出现的位置,维护最小距离. 代码 #include <cstdio> int c[30],n,p,a,minl; char ch; ...

  10. SpringMVC数据库链接池,以及其他相关配置

    1.applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans ...