1.CoreLocation 使用,获取当前位置
1.
ios7只要开始定位,系统就会自动要求你对应用程序授权
ios8之后,必须要代码中实现要求用户对应用程序授权 ,在plist中添加以下两个属性
NSLocationWhenInUseDescription,允许在前台获取GPS的描述
NSLocationAlwaysUsageDescription,允许在后台获取GPS的描述
2,代码
#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
@interface ViewController ()<CLLocationManagerDelegate>
@property(nonatomic,strong)CLLocationManager*manger;
@end
@implementation ViewController
-(CLLocationManager*)manger
{
if (_manger==nil) {
_manger=[[CLLocationManager alloc]init];
}
return _manger;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.manger.delegate=self;
if ([[UIDevice currentDevice].systemVersion floatValue]>8.0) {
[self.manger requestAlwaysAuthorization];//后台运行的时候执行获取位置信息
//[self.manger requestWhenInUseAuthorization];//前台执行的时候获取位置信息
}
else
{
[self.manger startUpdatingLocation];
}
}
//授权状态改变的时候调用
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
if (status == kCLAuthorizationStatusNotDetermined) {
NSLog(@"等待用户授权");
}else if (status == kCLAuthorizationStatusAuthorizedAlways ||
status == kCLAuthorizationStatusAuthorizedWhenInUse)
{
NSLog(@"授权成功");
// 开始定位
[self.manger startUpdatingLocation];
}
else
{
NSLog(@"授权失败");
}
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
//如果只需要获取一次,可以获取位置之后就停止
[self.manger stopUpdatingLocation];
CLLocation *location=[locations lastObject];
NSLog(@"经度=%f,维度=%f 速度=%f ",location.coordinate.latitude,location.coordinate.longitude,location.speed);
}
@end
1.CoreLocation 使用,获取当前位置的更多相关文章
- Uwp Windows10获取设备位置(经纬度)
先在Package.appxmanifest中配置位置权限 2. 创建LocationManager类 using System; using System.Collections.Generic; ...
- js 如何在浏览器中获取当前位置的经纬度
这个有一定的误差哈,具体的误差是多少,有兴趣的朋友可以去测试下 直接上代码 index.html页面代码: <html> <head lang="en"> ...
- jq获取鼠标位置
jq获取鼠标位置 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- C++获取鼠标位置及全局检测鼠标行为
1.获取鼠标位置(在屏幕的位置) CPoint m_mouse; GetCursorPos(&m_mouse); 2. 屏幕转化为客户端(控件的相对位置)& 客户端位置转化为屏幕位置 ...
- android 获取当前位置
1. Android开发位置感知应用程序方式:1. GPS 定位 精确度高,仅适用于户外,严重消耗电量.如果手机内置GPS接受模块,即使手机处于信号盲区,依然可以获取位置信息. 2. NETW ...
- Selenium2学习-031-WebUI自动化实战实例-029-JavaScript 在 Selenium 自动化中的应用实例之四(获取元素位置和大小)
通过 JS 或 JQuery 获取到元素后,通过 offsetLeft.offsetTop.offsetWidth.offsetHeight 即可获得元素的位置和大小,非常的简单,直接上源码了,敬请参 ...
- jquery 获取鼠标位置
//获取鼠标位置 $(function(){ $('body').mousemove(function(e) { e = e || window.event; __xx = e.pageX || e. ...
- android EditText获取光标位置并安插字符删除字符
android EditText获取光标位置并插入字符删除字符1.获取光标位置int index = editText.getSelectionStart(); 2.在光标处插入字符int index ...
- Android EditText获取光标位置并插入字符删除字符
1.获取光标位置 int index = editText.getSelectionStart(); 2.在光标处插入字符 int index = editText.getSelectionStart ...
随机推荐
- C#读写SQL Server数据库图片
效果图: 下载链接: http://download.csdn.net/detail/u010312811/9492402 1.创建一个Winform窗体,窗体分为“数据上传”和“数据读取”两部分: ...
- poj 3984
http://poj.org/problem?id=3984 题目很简单,就是简单的BFS吧,主要的难点在于坐标的问题 这个呢,可以反其道而行之,就是你从(1,1)到(5,5),你肯定走过一次 走过一 ...
- 华为 MATE7 调试 LOCAT 日志不输出问题
[转]华为 MATE7 调试 LOCAT 日志不输出问题 http://www.cnblogs.com/glaivelee/p/4593221.html 用手机进行调试,在电脑上不显示logcat信息 ...
- Nginx如何设置拒绝或允许指定ip访问
location ~ /druid/ { #deny 192.168.1.1; allow 192.168.1.1; deny all; proxy_pass http://127.0.0.1:808 ...
- 使用swift 中的注意,不断完善中
1. 应该充分利用swfit的新特性 比如如果按照oc里的习惯,调用一个delegate中都optional函数应该这样写 if delegate != nil && delegate ...
- ACM/ICPC 之 用双向链表 or 模拟栈 解“栈混洗”问题-火车调度(TSH OJ - Train)
本篇用双向链表和模拟栈混洗过程两种解答方式具体解答“栈混洗”的应用问题 有关栈混洗的定义和解释在此篇:手记-栈与队列相关 列车调度(Train) 描述 某列车调度站的铁道联接结构如Figure 1所示 ...
- glib-2.49.4-msys-x86-staticLib.7z
glib-2.49.4 MSYS 静态库 编译 export LIBFFI_CFLAGS=" -I/usr/local/lib/libffi-3.2.1/include " \ e ...
- html中的alt和title用法区别
html中的alt和title用法区别 首先明确一下概念,alt是html标签的属性,而title既是html标签,又是html属性.title标签这个不用多说,网页的标题就是写在<title& ...
- ubuntu下安装mysql
现在的软件越来越好安装,尤其是在ubuntu下安装软件,更是没有技巧,只需要在联网的情况下使用apt-get inatll 即可.在决定安装mysql之前,要先确定系统是否已经安装mysql.如下图: ...
- Codeforces Round #370 (Div. 2)(简单逻辑,比较水)
C. Memory and De-Evolution time limit per test 2 seconds memory limit per test 256 megabytes input s ...