关于Core Location-ios定位
来源:互联网 发布:手机里程表计价软件 编辑:程序博客网 时间:2024/05/19 14:17
转自:http://blog.csdn.net/csj1987/article/details/6657468
IOS中的core location提供了定位功能,能定位装置的当前坐标,同时能得到装置移动信息。因为对定位装置的轮询是很耗电的,所以最好只在非常必要的前提下启动。
其中,最重要的类是CLLocationManager,定位管理。
其定位有3种方式:
1,GPS,最精确的定位方式,貌似iphone1是不支持的。
2,蜂窝基站三角定位,这种定位在信号基站比较秘籍的城市比较准确。
3,Wifi,这种方式貌似是通过网络运营商的数据库得到的数据,在3种定位种最不精确
使用方式:
1,引入CoreLocation的包,一般的默认模板里是没有的,所以需要手动导入。
2,通过启动CLLocationManager来启动定位服务,因为定位信息是需要轮询的,而且对于程序来说是需要一定时间才会得到的,所以翠玉lcationManager的操作大多都给委托来完成。
加载locationManager的代码:
- CLLocationManager *locationManager = [[CLLocationManager alloc] init];//创建位置管理器
- locationManager.delegate=self;
- locationManager.desiredAccuracy=kCLLocationAccuracyBest;
- locationManager.distanceFilter=1000.0f;
- //启动位置更新
- [locationManager startUpdatingLocation];
distanceFilter是距离过滤器,为了减少对定位装置的轮询次数,位置的改变不会每次都去通知委托,而是在移动了足够的距离时才通知委托程序,它的单位是米,这里设置为至少移动1000再通知委托处理更新。
startUpdatingLocation就是启动定位管理了,一般来说,在不需要更新定位时最好关闭它,用stopUpdatingLocation,可以节省电量。
对于委托CLLocationManagerDelegate,最常用的方法是:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation;
这个方法即定位改变时委托会执行的方法。
可以得到新位置,旧位置,CLLocation里面有经度纬度的坐标值,
同时CLLocation还有个属性horizontalAccuracy,用来得到水平上的精确度,它的大小就是定位精度的半径,单位为米。
如果值为-1,则说明此定位不可信。
另外委托还有一个常用方法是
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error ;
当定位出现错误时就会调用这个方法。
- 关于Core Location-ios定位
- 关于Core Location-ios定位
- 关于Core Location-ios定位
- 关于Core Location-ios定位
- 关于Core Location-ios定位
- IOS Core Location-ios定位
- IOS Core Location 定位功能
- ios-使用Core Location定位
- iOS Core Location 实现定位
- ios之Core Location定位功能
- ios-使用Core Location框架定位
- iOS定位服务Core Location使用详解
- Core Location定位
- Core Location定位
- IOS学习之Core Location定位和MapKit视图使用
- IOS Core Location
- ios-Core Location框架
- iOS Location 定位功能
- js的textarea中字体颜色改变
- 强大的PHP反射机制
- getXMLfromSd
- GLSL学习笔记
- myeclipse中servers配制(myeclipse tomcat/derby删除)
- 关于Core Location-ios定位
- Byte Buffers and Non-Heap Memory
- error C2440: “static_cast”: 无法从“void (__thiscall CTransparentWnd::* )(WPARAM,LPARAM)”转换为“LRESULT (__
- Perl 中的线程
- [Ruby] 配置Ruby开发环境
- UML类图关系全面剖析
- MS Sql Server中存储过程与触发器的安全隐患
- 闲着……学学写写汇编(只贴代码)(2)
- 关于coreLocation - 地理位置反向编码