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 ...
随机推荐
- Angular记录(8)
文档资料 箭头函数--MDN:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Functions/Arrow_fun ...
- DirectX11--HLSL编译着色器的三种方法
前言 本教程不考虑Effects11(FX11),而是基于原始的HLSL. 目前编译与加载着色器的方法如下: 使用Visual Studio中的HLSL编译器,随项目编译期间一同编译,并生成.cso( ...
- Angular4.x学习日志
码云链接:https://gitee.com/ccsoftlucifer/Angular4Study 1.部署环境 安装nodejs 安装angular脚手架程序 2.创建工程 ng new 项目名 ...
- Linux 文件格式转码工具
Linux 系统下文件编码转换格式工具 ICONV 下载 https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz 源码安装: $ ./con ...
- 小E浅谈丨区块链治理真的是一个设计问题吗?
在2018年6月28日Zcon0论坛上,“区块链治理”这个话题掀起了大神们对未来区块链治理和区块链发展的一系列的畅想. (从左至右,分别为:Valkenburgh,Zooko,Jill, Vitali ...
- 2018-2019-2 网络对抗技术 20165325 Exp1 PC平台逆向破解
2018-2019-2 网络对抗技术 20165325 Exp1 PC平台逆向破解(BOF实验) 实验有三个模块: (一)直接修改程序机器指令,改变程序执行流程: (二)通过构造输入参数,造成BOF攻 ...
- c++17 代码你能看懂吗?
------------------------------------------------------------------------------ #include <vector&g ...
- 手把手教你写vue插件并发布(二)
前记:上一篇 https://www.cnblogs.com/adouwt/p/9211003.html, 说到了一个完整的vue插件开发.发布的流程,总结下来就讲了这么一个事,如何注入vue, 如果 ...
- eclipse,代码中有错误,项目或者java类中却不显示红叉
修改eclipse代码提示级别1.单个项目修改项目上右键-->properties-->java compiler-->building-->enable project sp ...
- linux 下修改网关mac地址
以rtl8196e为例 eth0:mac 地址设为123456789012 # flash set hw_nic0_addr 123456789012 eth1:mac 地址设为1122334455 ...