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 使用,获取当前位置的更多相关文章

  1. Uwp Windows10获取设备位置(经纬度)

    先在Package.appxmanifest中配置位置权限 2. 创建LocationManager类 using System; using System.Collections.Generic; ...

  2. js 如何在浏览器中获取当前位置的经纬度

    这个有一定的误差哈,具体的误差是多少,有兴趣的朋友可以去测试下 直接上代码 index.html页面代码: <html> <head lang="en"> ...

  3. jq获取鼠标位置

    jq获取鼠标位置 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  4. C++获取鼠标位置及全局检测鼠标行为

    1.获取鼠标位置(在屏幕的位置)  CPoint m_mouse; GetCursorPos(&m_mouse); 2. 屏幕转化为客户端(控件的相对位置)& 客户端位置转化为屏幕位置 ...

  5. android 获取当前位置

    1. Android开发位置感知应用程序方式:1. GPS 定位     精确度高,仅适用于户外,严重消耗电量.如果手机内置GPS接受模块,即使手机处于信号盲区,依然可以获取位置信息. 2. NETW ...

  6. Selenium2学习-031-WebUI自动化实战实例-029-JavaScript 在 Selenium 自动化中的应用实例之四(获取元素位置和大小)

    通过 JS 或 JQuery 获取到元素后,通过 offsetLeft.offsetTop.offsetWidth.offsetHeight 即可获得元素的位置和大小,非常的简单,直接上源码了,敬请参 ...

  7. jquery 获取鼠标位置

    //获取鼠标位置 $(function(){ $('body').mousemove(function(e) { e = e || window.event; __xx = e.pageX || e. ...

  8. android EditText获取光标位置并安插字符删除字符

    android EditText获取光标位置并插入字符删除字符1.获取光标位置int index = editText.getSelectionStart(); 2.在光标处插入字符int index ...

  9. Android EditText获取光标位置并插入字符删除字符

    1.获取光标位置 int index = editText.getSelectionStart(); 2.在光标处插入字符 int index = editText.getSelectionStart ...

随机推荐

  1. java web 学习 --第二天(Java三级考试)

    第一天的学习在这http://www.cnblogs.com/tobecrazy/p/3444474.html 2.jsp 基础知识 Jsp页面中的Java脚本主要有3部分:声明(Declaratio ...

  2. 2014北大研究生推免机试(校内)-复杂的整数划分(DP进阶)

    这是一道典型的整数划分题目,适合正在研究动态规划的同学练练手,但是和上一个随笔一样,我是在Coursera中评测通过的,没有找到适合的OJ有这一道题(找到的ACMer拜托告诉一声~),这道题考察得较全 ...

  3. Angular中使用Rainbow

    在使用js类库和框架的时候,大家都习惯于编写自己的使用示例,如果能将示例中的html,js和css 进行展示, 并进行高亮显示,效果会很棒,例如在html高亮显示jquery代码 上面的示例是使用ra ...

  4. SUSE下FTP服务器搭建

    FTP(File Transfer Protocol),是TCP/IP网络上两台计算机传送文件的协议,是在TCP/IP网络和Internet上最早使用的协议之一,属于网络协议组的应 用层.FTP客户机 ...

  5. css实现图片闪光效果

    1.这个效果是看到京东商城上的一个下效果,原本的思路是 用js控制一个图片在某张需要闪光的图片上重复出现,但是 网上找了一些资料,竟然是用css写的,真是太帅了!!! 2.原理:在需要闪光的图片前添加 ...

  6. 【leetcode】Reverse Words in a String(hard)☆

    Given an input string, reverse the string word by word. For example,Given s = "the sky is blue& ...

  7. 【网络】ssl与ssh

    ssh(安全外壳协议):百度百科 ssl(安全套接字):http://kb.cnblogs.com/page/162080/ https应用了ssl协议 ssh与ssl的区别:http://blog. ...

  8. LeetCode 242 Valid Anagram

    Problem: Given two strings s and t, write a function to determine if t is an anagram of s. For examp ...

  9. supersr--NSURLConnection iOS2.0苹果原生请求

    get请求1:   NSURL*url = [NSURLURLWithString:@"http://127.0.0.1/demo.json"];        NSURLRequ ...

  10. AI调色板

    AI新建图层时,要选择CMYK模式,才能出现如下图所示调色板,如果选RGB模式,那么调整颜色的时候只能通过输入RGB.