第一步,新建一个singleView的空白工程,如果新建,这里不做赘述了。

第二步:因为地图开发相关的framework:MapKit.frameworkCoreLocation.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 位置定位的更多相关文章

  1. jQuery学习笔记(控件位置定位、尺寸大小的获取等)

    想做一个幽灵按钮出来,效果大概如下图: 当点击按钮的时候,会有四根线条从四个方向飞入,经历从“无-有-无”的闪入过程. 那么我的设计想法是,先在HTML中定义一个按钮,然后在jQuery中设计按钮点击 ...

  2. 2013-10-25笔记,css: mini-width, 标准居中,样式中*号使用,背景图像位置定位

    mini-width:设置元素的最小宽度.該屬性值會對元素的寬度設置一個最小限制.因此,元素可以比制定值寬,但不能比制定值窄.不允許指定負值. 完美的居中佈局: body{text-align: ce ...

  3. Android - 位置定位(Location)服务(Service)类的基本操作

    位置定位(Location)服务(Service)类的基本操作 本文地址: http://blog.csdn.net/caroline_wendy 定位服务(Location Service),能够确 ...

  4. 简易的IOS位置定位服务

    有时一些小的需求,其实只是需要得知当前IOS APP使用的地点,有些只是想精确到城市级别,并不需要任何地图. 有了以下的简易实现: @interface MainViewController ()&l ...

  5. Android crash特殊位置定位

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 通常情况下,在我们开发的过程中遇到的crash,可以到logcat中找原因:如果做定制App,对方用 ...

  6. JS HTML标签尺寸距离位置定位计算

    四种浏览器对 clientHeight.offsetHeight.scrollHeight.clientWidth.offsetWidth 和 scrollWidth 的解释差异 网页可见区域宽:do ...

  7. Android开发之位置定位详解与实例解析(GPS定位、Google网络定位,BaiduLBS(SDK)定位)

    在android开发中地图和定位是很多软件不可或缺的内容,这些特色功能也给人们带来了很多方便.定位一般分为三种发方案:即GPS定位.Google网络定位以及基站定位 最简单的手机定位方式当然是通过GP ...

  8. 模拟位置 定位 钉钉打卡 运动轨迹 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  9. 微信小程序 位置定位position详解,相对定位relative,绝对定位absolute相关问题

    一.位置position[定位属性:static,relative,absolute,fixed,inherit,-ms-page,initial,unset] 1.static:元素框正常生成,块级 ...

随机推荐

  1. 关于XML文档的讲解

    1        XML的概述 1.1 什么是XML XML全称为Extensible Markup Language,意思是可扩展的标记语言.XML语法上和HTML比较相似,但HTML中的元素是固定 ...

  2. 关于JFace中的向导式对话框(WizardDialog类)

    向导式对话框是一种非常友好的界面,它能够引导用户一步步的输入信息.Eclipse的"新建项目",就是这样的向导式对话框. 在Eclipse中向导式对话框的开发是很简单的,它由Wiz ...

  3. ASP实现用年月日时分秒和两位随机数字来作为上传文件名的函数

    Public Function GetNewFileName() dim ranNum dim dtNow dtNow=Now() randomize ranNum=int(90*rnd)+10 Ge ...

  4. Android线控的使用

    实现方式一:只能在程序为前台时监控 在Activity中即可监听 @Override public boolean onKeyUp(int keyCode, KeyEvent event) { Log ...

  5. Decorator设计模式浅谈

    装饰类跟基础组件都实现了目标接口,是为了匹配正确的类型.Java中的IO设计就是典型的Decorator设计模式. 装饰模式产生的初衷是, 对默认实现类的行为进行扩展. 由于装饰类的构造器接受的参数是 ...

  6. php Composer中国全量镜像

    http://pkg.phpcomposer.com/ http://www.yiichina.com/doc/guide/2.0/intro-upgrade-from-v1 https://getc ...

  7. 40个Java集合面试问题和答案【中】【转载】

    接上文:http://www.cnblogs.com/xujianbo/p/5148075.html   16.UnsupportedOperationException是什么? Unsupporte ...

  8. ajax.abort 终止AJAX请求

                               $(document).ready(function () { var ajax; $('#choice').change(function() ...

  9. 代理的使用 一(helloworld级别)

    个人理解(估计,半年一年后,在看到这篇文章的时候,会觉得,当时真的弱爆了) 当我们自定义view的时候,比如说view上面有几个按钮,那么我们在别的地方使用这个view的时候,怎么来处理这些点击事件呢 ...

  10. IO流05_OutputStream和Writer输出流

    [输出流中的字节流和字符流] [OutPutStream和Writer] [ OutputStream和Writer中包含的方法 ] void write(int c)       将指定的字节/字符 ...