关于Core Location-ios定位
2015-05-07 09:10
459 查看
IOS中的core location提供了定位功能,能定位装置的当前坐标,同一时候能得到装置移动信息。由于对定位装置的轮询是非常耗电的,所以最好仅仅在非常必要的前提下启动。
当中,最重要的类是CLLocationManager,定位管理。
其定位有3种方式:
1,GPS,最精确的定位方式,貌似iphone1是不支持的。
2,蜂窝基站三角定位,这样的定位在信号基站比較秘籍的城市比較准确。
3,Wifi,这样的方式貌似是通过网络运营商的数据库得到的数据,在3种定位种最不精确
使用方式:
1,引入CoreLocation的包,一般的默认模板里是没有的,所以须要手动导入。
2,通过启动CLLocationManager来启动定位服务,由于定位信息是须要轮询的,并且对于程序来说是须要一定时间才会得到的,所以翠玉lcationManager的操作大多都给托付来完毕。
载入locationManager的代码:
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 ;
当定位出现错误时就会调用这种方法。
当中,最重要的类是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];desiredAccuracy为设置定位的精度,能够设为最优,装置会自己主动用最精确的方式去定位。
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定位
- 【iOS】7.4 定位服务->2.1.3.3 定位 - 官方框架CoreLocation 功能3:区域监听
- iOS 自带定位功能CoreLocation
- 快速入门:CoreLocation框架进行定位和iOS不同版本间定位的差异
- IOS 定位初步(CoreLocation)
- iOS项目开发— CoreLocation的定位服务和地理编码与发编码实现
- IOS学习之Core Location定位和MapKit视图使用
- 【iOS】7.4 定位服务->2.1.3.2 定位 - 官方框架CoreLocation 功能2:地理编码和反地理编码
- IOS CoreLocation框架的使用(用于地理定位)
- 【iOS】7.4 定位服务->2.1.3.1 定位 - 官方框架CoreLocation 功能1:地理定位
- [iOS 利用MapKit和CoreLocation框架打造精简的定位和导航]
- iOS定位服务CoreLocation
- iOS CoreLocation 实现简单定位(现实城市)
- ios之Core Location定位功能
- IOS Core Location 定位功能
- IOS学习之十二:Core Location定位和MapKit视图使用
- iOS CoreLocation定位 使用方法
- 【iOS】7.4 定位服务->2.1.3.3 定位 - 官方框架CoreLocation 功能3:区域监听
- iOS开发 - CoreLocation地理定位