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:元素框正常生成,块级 ...
随机推荐
- Android 自定义View修炼-Android中常见的热门标签的流式布局的实现
一.概述:在日常的app使用中,我们会在android 的app中看见 热门标签等自动换行的流式布局,今天,我们就来看看如何 自定义一个类似热门标签那样的流式布局吧(源码下载在下面最后给出哈) 类似的 ...
- [转]javascript指定事件处理程序包括三种方式:
javascript指定事件处理程序包括三种方式: (1):DOM0级事件处理程序 如: 代码如下: var btn=document.getElementById("mybtn" ...
- StringBuilder 用法和div获取
StringBuilder strHtml = new StringBuilder(); strHtml.Append("<tr>"); strHtml.Append( ...
- posix thread互斥量
互斥量 互斥量(Mutex)是“mutual exclusion”的缩写.互斥量是实现线程同步,和保护同时写共享数据的主要方法.使用互斥量的典型顺序如下:1. 创建和初始一个互斥量 2. 多个线程尝试 ...
- java1.5新特性
一:增强for循环 增强for的格式:for(数据类型 变量名:集合或者 数组){ } 传统的for循环可以对数组进行遍历: for(int x=0;x { Syste ...
- cell函数总结
元胞数组: 元胞数组是MATLAB的一种特殊数据类型,可以将元胞数组看做一种无所不包的通用矩阵,或者叫做广义矩阵.组成元胞数组的元素可以是任何一种数据类型的常数或者常量,每一个元素也可以具有不同的尺寸 ...
- 为ubuntu只带的network-manager添加latp/ipsec VPN
sudo apt-add-repository ppa:seriy-pr/network-manager-l2tp sudo apt-get update sudo apt-get install n ...
- 关于post请求参数的大小限制的说明
最近做一个上传图片的项目,前端使用jquery 的post提交,然后把上传的图片的base64码 传到后台,发现几KB或者几十KB的图片,都可以传到后台,但是在上传几M 的图片在后台接收的时候,发现传 ...
- ckeditor
去掉编辑器的下边栏 在config.js中加入: config.removePlugins = 'elementspath'; config.resize_enabled = false; 就ok了 ...
- 【高性能服务器】Tomcat剖析
引言 Tomcat是一个流行的servlet容器,对于开发人员来说整体和容器打交道有必要花一些时间爱你了解其内部结构.本文将从一下几个方面来剖析其内部结构. 整体结构 连接器 初始化过程 如何处理一个 ...