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);
    }
    
  • 相关阅读:
    [Noi2011]阿狸的打字机
    Bzoj3530: [Sdoi2014]数数
    Bzoj2037: [Sdoi2008]Sue的小球
    Bzoj4869: [Shoi2017]相逢是问候
    Bzoj1899: [Zjoi2004]Lunch 午餐
    Bzoj3884: 上帝与集合的正确用法
    UVA10692:Huge Mods
    Bzoj1009: [HNOI2008]GT考试
    Bzoj1212: [HNOI2004]L语言
    【国家集训队2012】tree(伍一鸣)
  • 原文地址:https://www.cnblogs.com/gchlcc/p/5843959.html
Copyright © 2011-2022 走看看