iOS8之后CoreLocation定位的使用
在Info.plist文件中添加如下配置:
//始终允许访问位置信息
(1)NSLocationAlwaysUsageDescription
//使用应用程序期间允许访问位置数据
(2)NSLocationWhenInUseUsageDescription
//创建一个管理者
- (CLLocationManager *)manager
{
if (!_manager) {
_manager = [[CLLocationManager alloc] init];
_manager.delegate = self;
// 授权使应用在前台后台都能使用定位服务
[_manager requestAlwaysAuthorization];
// _manager.desiredAccuracy = kCLLocationAccuracyBest;
// _manager.distanceFilter = 10;
}
return _manager;
}
//然后调用startUpdatingLocation方法
[self.manager startUpdatingLocation];
实现CLLocationManagerDelegate的代理方法
(1)获取到位置数据,返回的是一个CLLocation的数组,一般使用其中的一个
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
{
CLLocation *location = [locations firstObject];
NSLog(@"%f %f",location.coordinate.longitude,location.coordinate.latitude);
}
(2)获取用户位置数据失败的回调方法,在此通知用户
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{ if ([error code] == kCLErrorDenied)
{ //访问被拒绝
}
if ([error code] == kCLErrorLocationUnknown)
{ //无法获取位置信息
}
}
//反地理编码
//先懒加载CLGeocoder对象
- (CLGeocoder *)geoCoder
{
if (!_geoCoder) {
_geoCoder = [[CLGeocoder alloc] init];
}
return _geoCoder;
}
//完成定位后会调用
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations { self.location = [locations firstObject];
//开始反地理编码
[self.geoCoder reverseGeocodeLocation:self.location completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) { CLPlacemark *placemark = [placemarks firstObject]; self.placemark = placemark; }]; }
iOS8之后CoreLocation定位的使用的更多相关文章
- iOS8中使用CoreLocation定位[转]
本文转自:http://blog.devzeng.com/blog/ios8-corelocation-framework.html iOS8以前使用CoreLocation定位 1.首先定义一个全局 ...
- CoreLocation定位技术
CoreLocation框架可用于定位设备当前经纬度,通过该框架,应用程序可通过附近的蜂窝基站,WIFI信号或者GPS等信息计算用户位置. iOS定位支持的3种模式. (1)GPS ...
- iOS - CoreLocation 定位
前言 NS_CLASS_AVAILABLE(10_6, 2_0) @interface CLLocationManager : NSObject 1.CoreLocation 定位 配置 1.在 iO ...
- iOS8中的定位服务
iOS8中的定位服务 My app that worked fine in iOS 7 doesn't work with the iOS 8 SDK. CLLocationManager doesn ...
- 地图定位IOS8之后的定位
从ios8开始,苹果进一步加强了对用户隐私的保护. 当app想要访问用户的隐私信息时 系统不再自动弹出一个对话框让用户授权 解决方法: (1)调用ios8.0的API 主动请求用户授权 - (voi ...
- iOS开发拓展篇—CoreLocation定位服务
iOS开发拓展篇—CoreLocation定位服务 一.简单说明 1.CLLocationManager CLLocationManager的常用操作和属性 开始用户定位- (void)startUp ...
- Ios8之后, 定位的delegate不能触发的问题
if([CLLocationManager locationServicesEnabled]){ self.locationManage = [[[CLLocationManager alloc] i ...
- iOS-----使用CoreLocation定位
使用CoreLocation定位 CoreLocation框架 (CoreLocation.framework)可用于定位设备当前经纬度, 通过该框架, 应用程序可通过附近的蜂窝基站\WIFI信号 或 ...
- ios8 - CoreLocation定位服务的变化
在iOS8开发中,发现一个CoreLocation的使用问题,执行操作之后,不会调用到定位之后的delegate方法中. 根据文档,需要在使用CoreLocation前调用方法: [locationm ...
随机推荐
- hdu 4604 Deque(最长上升与下降子序列-能够重复)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4604 这个题解有点问题,暂时没时间改,还是参考别人的吧 #include <cstdio> ...
- JavaScript 操作 DOM 常用 API 总结
文本整理了javascript操作DOM的一些常用的api,根据其作用整理成为创建,修改,查询等多种类型的api,主要用于复习基础知识,加深对原生js的认识. 基本概念 在讲解操作DOM的api之前, ...
- Android eclipse下数据开源框架GreenDao的配置
1.前言 ORM(Object-RelationMapping,对象关系映射),是一种为了解决面向对象与数据库存在的互一匹配的现象的技术,通过描述对象和关系数据库之间的映射,将程序中的对象自动持久化到 ...
- App抓包数据包之Paros的安装及使用
1.在应用程序开发过程中,会遇到很多网络访问问题,自己没有能力提供后台服务,这时就可以抓取网络上的数据包,获取数据接口,应用在程序中.下面介绍使用paros抓取网络数据包得步骤. 2.要使用paros ...
- JAVA大数类
JAVA大数类api http://man.ddvip.com/program/java_api_zh/java/math/BigInteger.html#method_summary 不仅仅只能查J ...
- Error parsing XML: not well-formed (invalid token) 报错+R文件消失解决的方法
xml报错: 这个xml文件上右键source ->format 注意:res下的文件名称不能大写 R文件消失: 在攻克了其它问题的情况下(或者其它问题还没解决先凝视掉) 手动删除gen pro ...
- 开发Mhealth(即:Mobile Health 移动医疗)应用必知的10个掘金点
近 日,著名移动技术咨询公司Research2Guidance发布了最新版的<移动医疗应用开发者经济>报告.在过去的两年半里,iOS和Android 两大主流移动平台上的移动医疗应用(以下 ...
- matlab中的三维坐标系与旋转
1. matlab中的三维坐标系 matlab中的三维坐标系是使用的右手坐标系: 输入以下代码: >> plot3(0,0,0) >> xlabel('axis X') > ...
- JY02-HTML/CSS-京东01 定位是很粗暴的页面布局方法
1.学习重点 1. 独立完成开发前的准备工作 1.1 配置开发环境 已使用sublime,webstorm,,,vscode,ato,Hbuilder 1.2 建立项目文件 项目文件名/ css.js ...
- VB 中ListView 某一列的颜色添加不上去的解决方法
做过VB,对添加某一行中的某一列的背景颜色 ,和文字颜色,来表明某种意义的时候,会有添加不上去的情况 abc = Nothing abc = New ListViewItem.ListViewSubI ...