iOS学习笔记8-地图开发
两个主要框架
map kit 用于地图展示
core foundation 用于地理定位
LBS Location based service (基于定位的服务)
SoLoMo social local mobile
1.CLLocationManager
CLLocationManager的常用操作和属性
开始用户定位- (void)startUpdatingLocation;
停止用户定位- (void) stopUpdatingLocation;
说明:当调用了startUpdatingLocation方法后,就开始不断地定位用户的位置,中途会频繁地调用代理的下面方法
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;
每隔多少米定位一次
@property(assign, nonatomic) CLLocationDistance distanceFilter;
2.CLLocation
CLLocation用来表示某个位置的地理信息,比如经纬度、海拔等等
(1)经纬度
@property(readonly, nonatomic) CLLocationCoordinate2D coordinate;
(2)海拔
@property(readonly, nonatomic) CLLocationDistance altitude;
(3)路线,航向(取值范围是0.0° ~ 359.9°,0.0°代表真北方向)
@property(readonly, nonatomic) CLLocationDirection course;
(4)行走速度(单位是m/s)
@property(readonly, nonatomic) CLLocationSpeed speed;
(5)计算2个位置之间的距离
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location方法
定位精确度(越精确就越耗电)
@property(assign, nonatomic) CLLocationAccuracy desiredAccuracy;
3.CLLocationCoordinate2D
CLLocationCoordinate2D是一个用来表示经纬度的结构体,定义如下
typedef struct {
CLLocationDegrees latitude; // 纬度
CLLocationDegrees longitude; // 经度
} CLLocationCoordinate2D;
一般用CLLocationCoordinate2DMake函数来创建CLLocationCoordinate2D
if ([CLLocationManager locationServicesEnabled]) {
[self.locMgr startUpdatingLocation];
self.locMgr.distanceFilter = kCLDistanceFilterNone;
self.locMgr.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
}
代理
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations