zoukankan      html  css  js  c++  java
  • iOS地图 -- 定位中的CLLocation的介绍与小练习

    通过定位练习,熟悉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);
    }
    
  • 相关阅读:
    一道华为笔试题--内存块排序
    正则表达式
    Paxos算法的一个简单小故事
    Zookeeper中的Leader选取机制
    CCF201604-2俄罗斯方块
    Mybatis----Mapper.xml中的输入映射
    Mybatis----mybatis的全局配置文件SqlMapConfig.xml的配置
    Mybatis----开发dao
    Mybatis----入门程序
    Spring----面向切面编程和通知类型
  • 原文地址:https://www.cnblogs.com/gchlcc/p/5843959.html
Copyright © 2011-2022 走看看