CLLocationManager 位置定位
第一步,新建一个singleView的空白工程,如果新建,这里不做赘述了。
第二步:因为地图开发相关的framework:MapKit.framework、CoreLocation.framework, 至于如何添加,一般的ios相关博客都是有介绍。
在主界面的控制器 ViewController.h 文件中,我们啥也不做,.m文件中,我们需声明一个 CLLocationManager* locationManager的属性,我们让其实现CLLocationManagerDelegate的协议,并覆写其更新位置的方法,如下
1 #import "ViewController.h"
2 #import <CoreLocation/CoreLocation.h>
3 @interface ViewController ()<CLLocationManagerDelegate>{
4
5 }
6
7 @property (nonatomic,retain)CLLocationManager* locationManager;
8
9 @end
10
11 @implementation ViewController
12
13 -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
14
15 {
16 if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
17 NSLog(@"nibName: %@ bundle: %@",nibBundleOrNil,nibBundleOrNil);
18 _locationManager = [[CLLocationManager alloc] init];
19
20 }
21
22 return self;
23 }
24
25 - (void)dealloc
26 {
27 self.locationManager = nil;
28 [super dealloc];
}
29 - (void)viewDidLoad
30 {
31 [super viewDidLoad];
32 Do any additional setup after loading the view, typically from a nib.
33 delegate
34 self.locationManager.delegate = self;
35 The desired location accuracy.
36 self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
37 Specifies the minimum update distance in meters.
38
39 self.locationManager.distanceFilter = kCLDistanceFilterNone;
40
41 self.locationManager.purpose = @"To provide functionality based on user's current location.";
42
43 [self.locationManager startUpdatingLocation];
44 }
45
46 - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
47 NSLog(@"didChangeAuthorizationStatus---%u",status);
48 }
49
50 - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
51 NSLog(@"didChangeAuthorizationStatus----%@",error);
52 }
53
54 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
55 UIAlertView* av = [[UIAlertView alloc] initWithTitle:@"update" message:[NSString stringWithFormat:@"didUpdateToLocation: newLocation: %@ old:%@",newLocation,oldLocation] delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil nil];
56 [av show];
57 [av release];
}
CLLocationManager 位置定位的更多相关文章
- jQuery学习笔记(控件位置定位、尺寸大小的获取等)
想做一个幽灵按钮出来,效果大概如下图: 当点击按钮的时候,会有四根线条从四个方向飞入,经历从“无-有-无”的闪入过程. 那么我的设计想法是,先在HTML中定义一个按钮,然后在jQuery中设计按钮点击 ...
- 2013-10-25笔记,css: mini-width, 标准居中,样式中*号使用,背景图像位置定位
mini-width:设置元素的最小宽度.該屬性值會對元素的寬度設置一個最小限制.因此,元素可以比制定值寬,但不能比制定值窄.不允許指定負值. 完美的居中佈局: body{text-align: ce ...
- Android - 位置定位(Location)服务(Service)类的基本操作
位置定位(Location)服务(Service)类的基本操作 本文地址: http://blog.csdn.net/caroline_wendy 定位服务(Location Service),能够确 ...
- 简易的IOS位置定位服务
有时一些小的需求,其实只是需要得知当前IOS APP使用的地点,有些只是想精确到城市级别,并不需要任何地图. 有了以下的简易实现: @interface MainViewController ()&l ...
- Android crash特殊位置定位
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 通常情况下,在我们开发的过程中遇到的crash,可以到logcat中找原因:如果做定制App,对方用 ...
- JS HTML标签尺寸距离位置定位计算
四种浏览器对 clientHeight.offsetHeight.scrollHeight.clientWidth.offsetWidth 和 scrollWidth 的解释差异 网页可见区域宽:do ...
- Android开发之位置定位详解与实例解析(GPS定位、Google网络定位,BaiduLBS(SDK)定位)
在android开发中地图和定位是很多软件不可或缺的内容,这些特色功能也给人们带来了很多方便.定位一般分为三种发方案:即GPS定位.Google网络定位以及基站定位 最简单的手机定位方式当然是通过GP ...
- 模拟位置 定位 钉钉打卡 运动轨迹 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- 微信小程序 位置定位position详解,相对定位relative,绝对定位absolute相关问题
一.位置position[定位属性:static,relative,absolute,fixed,inherit,-ms-page,initial,unset] 1.static:元素框正常生成,块级 ...
随机推荐
- Java基础知识强化之网络编程笔记14:TCP之多个客户端上传到一个服务器的思考(多线程改进)
1. 多个客户端上传到一个服务器的思考 通过while循环可以改进一个服务器接收多个客户端. 但是这个是有问题的.如果是这种情况,假设我还有张三,李四,王五这三个人分别执行客户端 张三:好好学习.a ...
- vim高亮显示
在当期用户的主目录下创建文件.vimrc,打开编辑内容(~/.vimrc): filetype on syntax on
- SQL Server用存储过程新建视图
CREATE PROCEDURE [dbo].[p_GetV_view]ASBEGIN DECLARE @sqlstr1 varchar(255) DECLARE @sqlstr2 varchar(2 ...
- 实现百度地图导航Demo的语音播报功能
上文中实现了在本地导入百度地图导航Demo,那么在此基础上如何实现导航的语音播报呢? 一.为该应用申请语音播报(也叫注册) http://developer.baidu.com/map/index.p ...
- React组件生命周期过程说明【转】
实例化 首次实例化 getDefaultProps getInitialState componentWillMount render componentDidMount 实例化完成后的更新 getI ...
- hive与hbase集成
http://blog.csdn.net/vah101/article/details/22597341 这篇文章最初是基于介绍HIVE-705.这个功能允许Hive QL命令访问HBase表,进行读 ...
- ibatis 到 MyBatis区别
http://blog.csdn.net/techbirds_bao/article/details/9235309 简介: 本文主要讲述了 iBatis 2.x 和 MyBatis 3.0.x 的区 ...
- Android数据存储方式之SharedPreferences
Android平台给我们提供了一个SharedPreferences类,它是一个轻量级的存储类,特别适合用于保存软件配置参数.使用SharedPreferences保存数据,其背后是用xml文件存放数 ...
- C#字符串拼接怎么转义背景图片
C#字符串拼接怎么转义背景图片 StringBuilder sb = new StringBuilder(); sb.Append("<div style=\"backg ...
- Java_Web_request.setAttribute("result",username);
request.setAttribute("result",username); 在request对象中加入名为result的属性并附值为username,因为request对象是 ...