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 ...
随机推荐
- 面试经验合集-Web前端<一>
面试一:MF时间:2019-1-2 试题一 // [mf: stringify-query-string] // 类型: x z // 时长: 15 分钟 // 姓名: // 日期: // 实现下面的 ...
- python 中获取列表的索引
1.index方法 list_a= [12,213,22,2,32]for a in list_a: print(list_a.index(a)) 结果: 0 1 2 3 4 如果列表的没有重复的话那 ...
- 友盟统计单页面应用vue
根据友盟官方提示在index.html的body标签末尾加入相关代码后: 后来发现,由于项目为单页面应用,在路由发生跳转时(到其他页面了),并不会重新将新页面加入统计中.需要在App.vue页面中,监 ...
- 使用Sales_data类
写一段程序程序实现求两次交易相加结果的功能.程序的输入是下面这两条交易记录: 0-201-783456-X 3 20.00 0-201-783456-X 3 25.00 程序的结构如下: #inclu ...
- vue 生命周期详解
- BH1750FVI调试
在写此博客之前已经看了几遍数据手册了,现在已经调试成功了,可以读出来数据,还有不如意的地方,写此博客整理下思路. 1.BH1750fvi介绍. 这是一个16bit的数字传感器,使用I2C作为通信接口, ...
- [工具开发] 分享两个基于Heapster 和 Influxdb 的 Grafana 监控仪表盘模板
Info Collector: Heapster - /heapster- --metric-resolution=30s- --sink=influxdb:http://influxdb.defau ...
- python 识别图片文字
今天群里有兄弟问如何把图片的文字给识别出来 对于python来说这不是小菜一碟吗,于是乎让pupilheart狠狠的吹了一波(哈哈,竟然没懂),下面将整个实现过程给大家实现下: 方法一:自己搞定ORC ...
- Selenium-WebDriver框架常用基本操作
1.基础元素定位的八种方法 WebDriver driver = new ChromeDriver(); WebElement element = new WebElement(); 1.1 By.i ...
- -bash: yum: command not found
在学习Linux时,发现yum命令无法执行.便查了下,整理成文. yum介绍 Yum(全称为 Yellow dogUpdater, Modified)是一个在Fedora和RedHat以及CentOS ...