2013/4/22记录:

注意:如非必要,不应该多次轮询位置信息i
使用时,可根据需要制定精度,通过仔细制定所需的绝对最低精度级别,可以纺织不必要的电池消耗。 
 

导入:CoreLocation.framework
导入头文件:#import <CoreLocation/CoreLocation.h>
实现CLLocationManagerDelegate协议
 
   self.locationManager= [[CLLocationManager alloc] init];    //位置管理器实例
locationManager.delegate = self; //设置委托
locationManager.desiredAccuracy = kCLLocationAccuracyBest; //设置请求制定精度级别,精度越高越耗电
[locationManager startUpdatingLocation]; //启动

回调方法:

#pragma mark -
#pragma mark CLLocationManagerDelegate Methods
//当这个实施时下面那个就失效。
//- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
//
//}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation { if (startingPoint == nil) //如果没有开始坐标,选择刚定位到的坐标作为开始坐标
self.startingPoint = newLocation; //纬度值
NSString *latitudeString = [NSStringstringWithFormat:@"%g\u00B0",
newLocation.coordinate.latitude]; //“\u00B0”:角度符的Unicode表示形式
latitudeLabel.text = latitudeString; //经度值
NSString *longitudeString = [NSStringstringWithFormat:@"%g\u00B0",
newLocation.coordinate.longitude];
longitudeLabel.text = longitudeString; //以coordinate为中心的圆的半径
NSString *horizontalAccuracyString = [NSStringstringWithFormat:@"%gm",
newLocation.horizontalAccuracy];
horizontalAccuracyLabel.text = horizontalAccuracyString; //海拔
NSString *altitudeString = [NSStringstringWithFormat:@"%gm",
newLocation.altitude];
altitudeLabel.text = altitudeString; //海拔方面的精度
NSString *verticalAccuracyString = [NSStringstringWithFormat:@"%gm",
newLocation.verticalAccuracy];
verticalAccuracyLabel.text = verticalAccuracyString; //更新位置的时间戳
NSLog(@"%lf\n",newLocation.timestamp.timeIntervalSince1970); //两位置距离
CLLocationDistance distance = [newLocation
distanceFromLocation:startingPoint];
NSString *distanceString = [NSStringstringWithFormat:@"%gm", distance];
distanceTraveledLabel.text = distanceString; //停止
[self.locationManager stopUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error {
NSString *errorType = (error.code == kCLErrorDenied) ?
@"Access Denied" : @"Unknown Error";
UIAlertView *alert = [[UIAlertViewalloc]
initWithTitle:@"Error getting Location"
message:errorType
delegate:nil
cancelButtonTitle:@"Okay"
otherButtonTitles:nil];
[alert show];
}

Core Location实现定位的更多相关文章

  1. iOS 苹果自带地图定位Core Location

    Core Location是iOS SDK中一个提供设备位置的框架.可以使用三种技术来获取位置:GPS.蜂窝或WiFi.在这些技术中,GPS最为精准,如果有GPS硬件,Core Location将优先 ...

  2. iPhone的定位技术与Core Location框架

    来源:http://www.cnblogs.com/lovecode/archive/2011/12/24/2300579.html iPhone定位来源通常有:1. GPS定位 2. WiFi定位 ...

  3. 关于Core Location-ios定位

    IOS中的core location提供了定位功能,能定位装置的当前坐标,同一时候能得到装置移动信息.由于对定位装置的轮询是非常耗电的,所以最好仅仅在非常必要的前提下启动. 当中,最重要的类是CLLo ...

  4. Core Location :⽤用于地理定位

    Core Location :⽤用于地理定位 在移动互联⽹网时代,移动app能解决⽤用户的很多⽣生活琐事,⽐比如 导航:去任意陌⽣生的地⽅方 周边:找餐馆.找酒店.找银⾏行.找电影院 在上述应⽤用中, ...

  5. iOS开发-Core Location和Map Kit

    一.Core Location确定物理位置 利用以下3种技术: 1.GPS(最精确的) 2.蜂窝基站ID定位(cell ID Location) 3.WPS(Wi-Fi Positioning Ser ...

  6. IOS开发之Core Location

    IOS 支持三种检测当前位置的方式:手机基站.Wi-Fi.和GPS,其中GPS是经度最高的,同时也是最耗费手机电量的.一般情况下在室内是无法通过GPS获 取位置信息的,通过Wi-Fi获取位置的原理是通 ...

  7. Core Location Framework学习

    在Apple开发中,尤其是移动设备开发,经常会使用Core Location Framework,这个框架可以使得iOS设备获取当前的地理位置.本文就具体到Core Location 框架中,查看其声 ...

  8. Core Location和MapKit的一些简单使用

      Core Location 1. 基本对象是CLLocation,有属性coordinate, altitude, horizontal/vertical Accuracy, timestamp, ...

  9. ios中Core Location跟Map Kit的基本使用

    地图类开发应用中,离不开地理位置跟MKMapView的使用,下面就记录下自己在使用这两个东西中学到的. 不过并不是所有苹果的设备都支持地理位置,我们在使用前应该做个判断,代码如下: BOOL loca ...

随机推荐

  1. J.U.C-三剑客[semaphore\CyclicBarrier\CountDownLatch]

    一.semaphore信号量,底层也是基于AQS 使用: /** * 可以理解为控制某个资源最多有多少个线程同时执行,(比如洗手间,并行与排队) * 如果满了只能等待直到其它资源释放(可以理解为并发量 ...

  2. 《11招玩转网络安全》之第四招:low级别的DVWA SQL注入

    以DVWA为例,进行手工注入,帮助读者了解注入原理和过程. 1.启动docker,并在终端中执行命令: docker ps -a docker start LocalDVWA docker ps 执行 ...

  3. 五十九、linux 编程—— I/O 多路复用 fcntl

    59.1 介绍 前面介绍的函数如,recv.send.read 和 write 等函数都是阻塞性函数,若资源没有准备好,则调用该函数的进程将进入阻塞状态.我们可以使用 I/O 多路复用来解决此问题(即 ...

  4. 五十六、linux 编程——UDP 编程模型

    56.1 UDP 编程模型 56.1.1 编程模型 UDP 协议称为用户数据报文协议,可靠性比 TCP 低,但执行效率高 56.1.2 API (1)发送数据 函数参数: sockfs:套接字文件描述 ...

  5. [置顶]Python开发之路

    阅读目录   第一篇:python入门 第二篇:数据类型.字符编码.文件处理 第三篇:函数 第四篇:模块与包 第五篇:常用模块 第六篇:面向对象 第七篇:面向对象高级 第八篇:异常处理 第九篇:网络编 ...

  6. robotframework环境安装

    1.安装 robotframework 执行命令 pip install robotframework 2.安装seleniumlibrary 执行命令 pip install --upgrade r ...

  7. 移除文件(git rm)

    git rm`命令会把文件从已跟踪列表(及暂存区)中移除,并且移除把文件从工作目录中移除,这样下一次你就不会在未跟踪文件列表中看到这些文件了. 如果你只是简单的把文件从工作目录移除,而没有使用git ...

  8. 前后端分离--ajaxUpload异步上传文件成功,前端获取数据却失败的解决方案

    转载:https://blog.csdn.net/baidu_32809053/article/details/78709951

  9. Python爬虫从入门到进阶(4)之xpath的使用

    官网地址:https://lxml.de/xpathxslt.html 导入: from lxml import etree lxml.tree 支持 ElementTree 和 Element 上的 ...

  10. NB群友

    链接:https://ac.nowcoder.com/acm/contest/625/A来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 131072K,其他语言26214 ...