iPhone中GPS定位如何使用

关键词

1.info.plist配置授权描述

2.引入库

3.CLLocationManager的使用

info.plist配置

在info.plist中根据情况加入以下两个string类型配置项,并填写描述

1.NSLocationAlwaysUsageDescription

2.NSLocationWhenInUseUsageDescription

引入库

-引入CoreLocation.framework

-在原文件中引入 <CoreLocation/CoreLocation.h>

代码实现


// 初始化 2.- (void)setupLocationManager { 3. _locationManager = [[CLLocationManager alloc] init]; 4. _locationManager.desiredAccuracy = kCLLocationAccuracyBest; 5. _locationManager.distanceFilter = kCLDistanceFilterNone; 6.
7. if ([_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { 8. [_locationManager requestWhenInUseAuthorization]; 9. } 10.} 11.
12.// 调用此方法开始定位 13.- (void) startUpdatingLocation { 14. if ([CLLocationManager locationServicesEnabled]) { 15. _shouldHandleLocation = YES; 16. _locationManager.delegate = self; 17. [_locationManager startUpdatingLocation]; 18. } else { 19. [SVProgressHUD showErrorWithStatus:@"请开启定位功能!"]; 20. } 21.} 22.
23.#pragma mark - CLLocationManagerDelegate 24.- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 25.{ 26. CLLocation *newLocation = [locations lastObject]; 27. if (_shouldHandleLocation) { 28. _shouldHandleLocation = NO; 29. _latitude = newLocation.coordinate.latitude; 30. _longitude = newLocation.coordinate.longitude; 31.
32. [self commitCheckinInfo]; 33. } 34.
35. _locationManager.delegate = nil; 36. [_locationManager stopUpdatingLocation]; 37.} 38.
39.- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 40.{ 41. [SVProgressHUD showErrorWithStatus:@"定位失败!"]; 42. _locationManager.delegate = nil; 43. [manager stopUpdatingLocation]; 44.}

[iPhone硬件]-GPS定位的使用的更多相关文章

  1. 如何利用【百度地图API】进行定位?非GPS定位

    原文:如何利用[百度地图API]进行定位?非GPS定位 如果你可以上网,如果你有火狐浏览器,那么恭喜你.你能很容易使用以下代码进行定位! ------------------------------- ...

  2. [置顶] xamarin android使用gps定位获取经纬度

    看了文章你会得出以下几个结论 1.android定位主要有四种方式GPS,Network(wifi定位.基站定位),AGPS定位 2.绝大部分android国产手机使用network进行定位是没有作用 ...

  3. 【Android】GPS定位基本原理浅析

    位置服务已经成为越来越热的一门技术,也将成为以后所有移动设备(智能手机.掌上电脑等)的标配.而定位导航技术中,目前精度最高.应用最广泛的,自然非GPS莫属了.网络上介绍GPS原理的专业资料很多,而本文 ...

  4. GPS定位基本原理浅析

    位置服务已经成为越来越热的一门技术,也将成为以后所有移动设备(智能手机.掌上电脑等)的标配.而定位导航技术中,目前精度最高.应用最广泛的,自然非GPS莫属了.网络上介绍GPS原理的专业资料很多,而本文 ...

  5. linux下编程epoll实现将GPS定位信息上报到服务器

    操作系统:CentOS 开发板:fl2440 开发模块:A7(GPS/GPRS),RT3070(无线网卡) ********************************************** ...

  6. 和菜鸟一起学android4.0.3源码之硬件gps简单移植【转】

    本文转载自:http://blog.csdn.net/mwj19890829/article/details/18751447 关于Android定位方式 android 定位一般有四种方法,这四种方 ...

  7. GPS定位 测试

    public class MainActivity extends Activity { private final String TAG = "BX"; private Loca ...

  8. Android中GPS定位的简单应用

    在Android中通过GPS获得当前位置,首先要获得一个LocationManager实例,通过该实例的getLastKnownLocation()方法获得第一个的位置,该方法的说明如下: void ...

  9. GPS定位为什么要转换处理?高德地图和百度地图坐标处理有什么不一样?

    GPS定位为什么要转换处理?高德地图和百度地图坐标处理有什么不一样? 先了解一下 高德地图 采用: GCJ-02 (不可逆) 百度百科: http://baike.baidu.com/link?url ...

随机推荐

  1. CentOS7 安装 mplayer

    我google找到这个方法可以简单快速安装 mplayer 和 vlc,centos 7 only. Please google the latest release for the followin ...

  2. vue2.0 实现click点击当前li,并动态添加class(这种方法不太喜欢)

    1,文件内容 ---- 使用v-for遍历数据 ---- @click="selectSort(item)"添加点击事件,并把每个obj=item传入 ---- v-show=&q ...

  3. deb包的2种安装安装方法

    一.cydia重启自动安装:用ifunbox进入//var/root/Media/Cydia/AutoInstallCydia/AutoInstall 需要分别单独建立,注意大小写.然后把你要安装的d ...

  4. 一款基于的jQuery仿苹果样式焦点图插件

    这次我们要分享的这款jQuery焦点图非常特别,它的外观特别简单,但是又相当大气.焦点图的整体样式是仿苹果样式的,由于jQuery的运用,我们只要点击图片下方的缩略图即可达到图片切换的焦点图特效,这款 ...

  5. postgresql解决锁表

    --查询是否锁表了select oid from pg_class where relname='可能锁表了的表'select pid from pg_locks where relation='上面 ...

  6. oracle 数据库中,应用程序里的连接探測语句的正确使用

    oracle 数据库中,应用程序里的连接探測语句的正确使用 本文为原创文章.转载请注明出处:http://blog.csdn.net/msdnchina/article/details/3851376 ...

  7. spark mysql读写

    val data2Mysql2 = (iterator: Iterator[(String, Int)]) => { var conn: Connection = null; var ps: P ...

  8. [driver]linux内核动态加载模块

    问题: 1. 把编译好的模块放到板子/lib/modules对应文件夹下,并且执行了depmod -a, 比如pl2303.ko, 那么下一次插入pl2303的串口线,是否可以识别,也就是自动加载pl ...

  9. [内核]Linux UserSpace和Kernel之间如何联系

    转自:http://blog.csdn.net/dreaming_my_dreams/article/details/8272586 应用层和驱动的衔接,一直是一个老大难问题,若弄不清楚,总觉得驱动写 ...

  10. JVM系统性能监控总结

    (1) uptime 查看系统运行时间.连接数(终端连接数).平均负载 (2) top 查看CPU.内存.交换空间使用情况,可以看到当前系统性能进程消耗资源情况 (3) vmstat 统计系统CPU. ...