Core Location实现定位
2013/4/22记录:
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实现定位的更多相关文章
- iOS 苹果自带地图定位Core Location
Core Location是iOS SDK中一个提供设备位置的框架.可以使用三种技术来获取位置:GPS.蜂窝或WiFi.在这些技术中,GPS最为精准,如果有GPS硬件,Core Location将优先 ...
- iPhone的定位技术与Core Location框架
来源:http://www.cnblogs.com/lovecode/archive/2011/12/24/2300579.html iPhone定位来源通常有:1. GPS定位 2. WiFi定位 ...
- 关于Core Location-ios定位
IOS中的core location提供了定位功能,能定位装置的当前坐标,同一时候能得到装置移动信息.由于对定位装置的轮询是非常耗电的,所以最好仅仅在非常必要的前提下启动. 当中,最重要的类是CLLo ...
- Core Location :⽤用于地理定位
Core Location :⽤用于地理定位 在移动互联⽹网时代,移动app能解决⽤用户的很多⽣生活琐事,⽐比如 导航:去任意陌⽣生的地⽅方 周边:找餐馆.找酒店.找银⾏行.找电影院 在上述应⽤用中, ...
- iOS开发-Core Location和Map Kit
一.Core Location确定物理位置 利用以下3种技术: 1.GPS(最精确的) 2.蜂窝基站ID定位(cell ID Location) 3.WPS(Wi-Fi Positioning Ser ...
- IOS开发之Core Location
IOS 支持三种检测当前位置的方式:手机基站.Wi-Fi.和GPS,其中GPS是经度最高的,同时也是最耗费手机电量的.一般情况下在室内是无法通过GPS获 取位置信息的,通过Wi-Fi获取位置的原理是通 ...
- Core Location Framework学习
在Apple开发中,尤其是移动设备开发,经常会使用Core Location Framework,这个框架可以使得iOS设备获取当前的地理位置.本文就具体到Core Location 框架中,查看其声 ...
- Core Location和MapKit的一些简单使用
Core Location 1. 基本对象是CLLocation,有属性coordinate, altitude, horizontal/vertical Accuracy, timestamp, ...
- ios中Core Location跟Map Kit的基本使用
地图类开发应用中,离不开地理位置跟MKMapView的使用,下面就记录下自己在使用这两个东西中学到的. 不过并不是所有苹果的设备都支持地理位置,我们在使用前应该做个判断,代码如下: BOOL loca ...
随机推荐
- sql0001
001. https://blog.csdn.net/qinshi965273101/article/details/81907658 002. https://blog.csdn.net/ ...
- 半导体知识:蚀刻(Etch)工艺讲解
本文转载自微信公众号 - 半导体行业观察 , https://mp.weixin.qq.com/s/F3LXiub6n4iYsQDqDH9K_g
- [Luogu P2296][NOIP 2014]寻找道路
emmm交了第8次才过. 这道题目测一道单源最短路问题,因此dijkstra或者spfa板子先准备好.因为题中对最短路有限定: 路径上的所有点的出边所指向的点都直接或间接与终点连通. 在满足条件1的情 ...
- ue4 staticMesh属性记录
Light Map Resolution 光照贴图分辨率 Generate Mesh Distancde Field 生成网格距离场(一种不怎么消耗性能的阴影) http://api.unrealen ...
- 移动端返回上一页,刚需!document.referrer 详解
返回上一页,在PC端我们可以使用:history.go(-1)或者history.back(),可以正常返回第一层.这样,我们不需要上一页的 url 具体是什么,只要使用 history 一般都没啥问 ...
- 【vue】组件使用Deferred特性
延迟加载组件 defer的意思是"延迟",所以deferred对象的含义就是"延迟"到未来某个点再执行. <template> <div> ...
- PostgreSQL学习笔记(二)-安装pgAdmin
继上篇安装PostgreSQL后,我们需要安装一个PostgreSQL的图形化管理工具. pgadmin管理工具 创建Python的虚拟环境 cd /root/venv python -m venv ...
- Visual Studio 2013 SDK 扩展之简介
Release Notes:[发行说明]启动记事本的扩展,以管理员身份运行验证通过. Getting Started Guide:[入门]使用[Ctrl + 1]更快捷打开记事本 More Info ...
- HtmlWebpackPlugin用的html的ejs模板文件中如何使用条件判断
折腾: [已解决]给react-hot-boilerplate中的index.html换成用HtmlWebpackPlugin自动生成html 期间,已经有了思路了,但是不知道如何在ejs的html中 ...
- WPF 10天修炼 第十天- WPF数据绑定
WPF数据绑定 数据绑定到元素属性是将源对象指定为一个WPF元素,并且源属性是一个依赖属性,依赖属性内置了变更通知.当改变源对象依赖属性值之后,绑定目标可以立即得到更新,开发人员不需要手动编写响应事件 ...