iOS地图 -- 定位中的CLLocation的介绍与小练习
2016-09-05 22:43
357 查看
通过定位练习,熟悉CLLocation
在上篇笔记中提到了CLLocation类,这里通过练习来讲解一下这个类,类中包含了获取到的用户位置的信息coordinate --> 坐标,经度和纬度
altitude --> 海拔
horizontalAccuracy --> 水平精度
verticalAccuracy -->垂直精度
course --> 航向
speed --> 速度
timestamp --> 时间戳
distanceFromLocation: --> 计算两个位置之间的距离
练习要求:
打印:北偏东 30度方向 走了100米
位置管理者的懒加载什么的就不在这里写了
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations { CLLocation *location = [locations lastObject]; // 打印:北偏东 30度方向 走了100米 // 1.计算方向 NSArray *arr = @[@"北偏东",@"东偏南",@"南偏西",@"西偏北"]; int index = (int)(location.course / 90); // course航向 NSString *direction = arr[index]; // 2.计算度数 int degree = (int)location.course % 90; if (degree == 0) { direction = [@"正" stringByAppendingString:[direction substringToIndex:1]]; } // 3.计算路程 double distance = 0; if (self.preivousLoc) { distance = [location distanceFromLocation:self.preivousLoc]; // 计算两点之间的距离 } self.preivousLoc = location; // 4.拼串 NSString *result; if (degree != 0) { result = [NSString stringWithFormat:@"%@ %zd度方向 走了%f米",direction,degree,distance]; } else { result = [NSString stringWithFormat:@"%@ 方向 走了%f米",direction,distance]; } NSLog(@"%@",result); }
相关文章推荐
- Map1: iOS开发中定位和地图介绍
- 【iOS】高德地图MAMapKit的使用:地图显示、添加大头针、导航、定位功能介绍
- IOS 开启定位功能 CLLocationManager 介绍-简单使用
- iOS之地图定位简单介绍
- iOS地图开发和定位
- IOS之地图和定位应用开发
- iOS 地图开发与定位
- iOS 6 开发---开发定位服务的App-在地图上标注位置
- IOS地图定位
- iOS开发之地图和定位应用开发
- iOS Cllocationmanger定位, 使用Google Map API在mapview上画路径
- iOS下CLLocationManager多次定位引起内存访问错误的问题解决
- ios 实现地图的定位,查询,自定义大头针
- IOS 地图 位置(简单介绍)
- ios中地图定位
- IOS定位核心与地图
- IOS之地图和定位应用开发
- IOS 地图位置定位
- IOS CLLocationManager和中国地图偏移(China Shift)
- [IOS地图开发系类]1、CLLocationManager 位置定位