- (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. Spring学习(三)——Spring中的依赖注入的方式

    [前面的话] Spring对我太重要了,做个关于web相关的项目都要使用Spring,每次去看Spring相关的知识,总是感觉一知半解,没有很好的系统去学习一下,现在抽点时间学习一下Spring.不知 ...

  2. [Aaronyang] 写给自己的WPF4.5 失传的第十本秘籍4[wpf使用FontAwesome,并送其他3招心法]

    总有一个人他教会你成长,然后又独自离开--Aaronyang的博客(www.ayjs.net)-www.8mi.me =============时隔两年后再看WPF,有些秘籍不太适合公开,公开了就不值 ...

  3. 传智168期JavaEE就业班 day04-dom

    * 课程回顾: * js语法 * js的动态函数和匿名函数 * js动态函数 Function new Function(); * 匿名函数:没有名称的函数,起个名称 var add = functi ...

  4. iOS运行时 -- Runtime(摘抄自网络)

    运行时(iOS) 一.什么是运行时(Runtime)? 运行时是苹果提供的纯C语言的开发库(运行时是一种非常牛逼.开发中经常用到的底层技术) 二.运行时的作用? 能获得某个类的所有成员变量 能获得某个 ...

  5. 获取Trustedinstalled权限.reg

    Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT*\shell\runas] @="获取TrustedInstaller权限&q ...

  6. ZOJ 3430 Detect the Virus

    传送门: Detect the Virus                                                                                ...

  7. CSU 1115 最短的名字

    传送门 Time Limit: 5000MS   Memory Limit: 65536KB   64bit IO Format: %lld & %llu Description 在一个奇怪的 ...

  8. c链表实现遇到的错误

    想完成一个链表发现有错误,代码如下: //http://ac.jobdu.com/problem.php?pid=1511 //֮ǰÓÃlistʵÏֵģ¬½ñÌìÊÔÒ»ÏÂÓÃstruct ...

  9. FatMouse的交易问题

    想按照某个值排序,用sort()函数,结果想了半天不知道用数组怎么解决,然后看了答案,才知道原来可以用struct,想想我真是笨死了.. 原题描述以及答案如下: Problem Description ...

  10. MySQL学习笔记01-MYSQL安装

    一 MySQL简介 MySQL是一个关系型数据库管理系统,由瑞典 MySQL AB 公司开发,目前属于 Oracle 公司. MySQL 最流行的关系型数据库管理系统. MySQL分为企业版和社区版. ...