【问题标题】:iPhone - How do i get direction with degree based locationiPhone - 我如何获得基于学位的位置的方向
【发布时间】:2025-12-09 07:15:02
【问题描述】:

首先,我在课堂上实现了位置管理器功能,并且运行良好,并为我提供了当前位置。从那个位置我知道了如何从here 获得位置度数。但我无法确定我也提到过this 的方向(即北、南、东、西)。我希望以度数显示的位置,方向格式如this。即位置经理给我 +37.33019332,-122.02298792,我想要 37° 19' 49"N, -122° 1' 23"E。我得到了所有的东西,只是不知道如何得到最后的“N”和“E”。 如果我为此使用CLLocation.course,我将获得我的指导课程。 任何帮助将不胜感激。

【问题讨论】:

    标签: iphone ios cllocationmanager


    【解决方案1】:

    这其实很简单。纬度从赤道的 0° 开始,北极为 90.0,南极为 -90.0。基本上,如果纬度在 0 到 90 之间,你在北半球和南半球,纬度在 0 到 -90 之间。

    经度基本上以相同的方式工作。 0° 是指本初子午线,它是假想的贯穿英国格林威治和非洲部分地区的线。 180°以内的正经度是指本初子午线以东的地区,而负经度是指本初子午线以西180°以内的地区。

    【讨论】:

    • 非常感谢。不知道那个。 :)
    【解决方案2】:

    使用此代码并将 CLLocationManagerDelegate 放在 .h 文件中

    - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
    {             
        updatedHeading = newHeading.magneticHeading;
        float headingFloat = 0 - newHeading.magneticHeading;
    
        rotateImg.transform = CGAffineTransformMakeRotation(headingFloat*radianConst);    
        float value = updatedHeading;
        if(value >= 0 && value < 23)
        {
            compassFault.text = [NSString stringWithFormat:@"%f° N",value];
        }
        else if(value >=23 && value < 68)
        {
            compassFault.text = [NSString stringWithFormat:@"%f° NE",value];
        }
        else if(value >=68 && value < 113)
        {
            compassFault.text = [NSString stringWithFormat:@"%f° E",value];
        }
        else if(value >=113 && value < 185)
        {
            compassFault.text = [NSString stringWithFormat:@"%f° SE",value];
        }
        else if(value >=185 && value < 203)
        {
            compassFault.text = [NSString stringWithFormat:@"%f° S",value];
        }
        else if(value >=203 && value < 249)
        {
            compassFault.text = [NSString stringWithFormat:@"%f° SE",value];
        }
        else if(value >=249 && value < 293)
        {
            compassFault.text = [NSString stringWithFormat:@"%f° W",value];
        }
        else if(value >=293 && value < 350)
        {
            compassFault.text = [NSString stringWithFormat:@"%f° NW",value];
        }
      }
    

    【讨论】:

    • 这将返回指南针方向。我不需要那个。无论如何,感谢您的帮助。
    • @Nims 但是这个是不正确的,因为它返回 NULL 为 0 到 360 度值..