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:元素框正常生成,块级 ...
随机推荐
- sql时间段算法
需求:领导要求写时间段算法,格式如下 :-: :-: :-: :-: :-: :-: :-: :-: :-: :-: :-: :-: :-: :-: :-: :-: 一小时制 :-: :-: :-: ...
- XStream将xml文件拼成字符串
1.引入的包 <dependency> <groupId>com.thoughtworks.xstream</groupId> <artifactId&g ...
- 各I/O模型 对应Web服务应用模型(select,poll,epoll,kevent,"/dev/poll")
一.利用select多路复用I/O的Web服务应用模型 /* 可读.可写.异常三种文件描述符集的申明和初始化.*/ fd_set readfds, writefds, exceptionfds; F ...
- Azure PowerShell (二)云服务
. 浏览云服务Get-AzureService | Select-Object -Property ServiceName, Location,`@{Name='ProdIP';Expression ...
- [原] Unity下的ElectroServer的连接
ES的版本是5.4.1,示例目录下code_examples\ConnectAndLoginManually是Unity的连接和登录代码. 除了host和port需要指定,在连接时需要指定连接方式,如 ...
- hackerrank Day15: Linked List
#include <iostream> #include <cstddef> using namespace std; class Node { public: int dat ...
- app测试点
手机上的app分为基于HTML5的app(类似于pc上的b/S应用)和本地app(类似于C/S结构). 所以测试上我们也可以充分吸收web的b/s和c/s测试经验.但是不同于pc上的应用测试,手机上的 ...
- Atom编辑器入门到精通(六) Markdown支持
尽管我们使用Atom主要是为了编写代码,不过Atom还支持编辑很多其他格式的文件. 比如Markdown和Asciidoc. 这一章中我们主要学习如何快速方便地编辑Markdown文件.另外在写这篇博 ...
- JAXB - XML Schema Types, Defining Types for XML Elements With Content
Content: A Value The content of an XML element may be some value, or one or more subordinate element ...
- ASP.NET Web Froms开发模式中实现程序集的延迟加载
延迟加载是一个很大的诱惑,可以达到一些比较好的效果,比如: 1.在实体框架中,由于关联数据的数量和使用时机是不确定的,通过延迟加载,仅在使用的时候去执行关联数据的查询操作,减少无谓的数据查询操作,可以 ...