第一步,新建一个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. CSS3 旋转的八卦图

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. Android自定义标题TitleView

    Android开发过程中,经常遇到一个项目需要重复的定义相同样式的标题栏,Android相继推出了actionBar, toolBar, 相信有用到的朋友也会遇到一些不如意的时候,比如标题栏居中时,需 ...

  3. OC中-数组是如何遍历的?

    #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool ...

  4. [Doc ID 1590988.1]如何清理E-Business Suite的缓存(Apache/iAS, Cabo, Modplsql, Browser, Jinitiator, Java, Portal, WebADI)?

    文档内容   目标   解决方案   参考 适用于: Oracle Applications Technology Stack - 版本 11.5.9 到 12.2.2 [发行版 11.5 到 12. ...

  5. jqzoom基于jQuery的图片放大镜

    1.引入jQuery和jqzoom插件 <script src="/js/common/jquery-1.6.2.js" type="text/javascript ...

  6. Win7下简约的Gif查看器 仅1.8M

    win7下面由于版权的原因把,默认打开gif的是ie浏览器,这个多么的不方便呀,我在网上淘到了这个程序,话说是从Xp中提取移植过来的.用起来很不错. 下载地址在: http://pan.baidu.c ...

  7. 从lambda到函数式编程

    Object.send(:remove_const,'TRUE') Object.send(:remove_const,'FALSE') def to_integer(pro) pro[-> n ...

  8. HttpWebRequest 上传图片

    public string HttpUploadFile() { string url = "http://localhost:50380/WebForm1.aspx"; stri ...

  9. 大数据架构:flume-ng+Kafka+Storm+HDFS 实时系统组合

    http://www.aboutyun.com/thread-6855-1-1.html 个人观点:大数据我们都知道hadoop,但并不都是hadoop.我们该如何构建大数据库项目.对于离线处理,ha ...

  10. rest的config

    <个人积累,转载请注明出处> 新手写rest wcf经常会报配置文件异常.我为了避免这种问题,将自己配好的config放这里,用的时候将ABC改成自己的,粘贴就行了. ABC是什么我就不赘 ...