Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone-如何通过基于学位的定位获得方向_Iphone_Ios_Cllocationmanager - Fatal编程技术网

iPhone-如何通过基于学位的定位获得方向

iPhone-如何通过基于学位的定位获得方向,iphone,ios,cllocationmanager,Iphone,Ios,Cllocationmanager,首先,我在我的类中实现了location manager函数,这些函数运行良好,并给出了当前位置。从那个位置我得到了如何从中获得位置度。但我也无法得到我提到的方向(即北、南、东、西)。我希望我要显示的位置以度为单位,方向格式如下。i、 e.位置经理给我+37.33019332,-122.02298792,我想要37°19'49“N,-122°1'23”e。我得到了所有的东西,只是不知道如何得到最后的“N”和“E”。 如果我使用CLLocation.course进行此操作,我将获得我的方向课程。

首先,我在我的类中实现了location manager函数,这些函数运行良好,并给出了当前位置。从那个位置我得到了如何从中获得位置度。但我也无法得到我提到的方向(即北、南、东、西)。我希望我要显示的位置以度为单位,方向格式如下。i、 e.位置经理给我+37.33019332,-122.02298792,我想要37°19'49“N,-122°1'23”e。我得到了所有的东西,只是不知道如何得到最后的“N”和“E”。 如果我使用
CLLocation.course
进行此操作,我将获得我的方向课程。
任何帮助都将不胜感激。

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


经度的工作原理基本相同。0°是指本初子午线,它是一条穿过英格兰格林威治和非洲部分地区的假想线。高达180°的正经度表示本初子午线以东的位置,而负经度表示本初子午线以西高达180°的区域。

使用此代码并将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];
    }
  }
-(void)locationManager:(CLLocationManager*)管理器已更新标题:(CLHeading*)新标题
{             
updatedHeading=newHeading.magneticeHeading;
float heading float=0-newHeading.magneticeheading;
RotateMg.transform=CGAffineTransformMakeRotation(headingFloat*弧度常数);
浮动值=更新的航向;
如果(值>=0&&value<23)
{
compassFault.text=[NSString stringWithFormat:@“%f°N”,值];
}
否则如果(值>=23&&value<68)
{
compassFault.text=[NSString stringWithFormat:@“%f°NE”,值];
}
否则如果(值>=68&&value<113)
{
compassFault.text=[NSString stringWithFormat:@“%f°E”,值];
}
否则如果(值>=113&&value<185)
{
compassFault.text=[NSString stringWithFormat:@“%f°SE”,值];
}
否则如果(值>=185&&value<203)
{
compassFault.text=[NSString stringWithFormat:@“%f°S”,值];
}
否则如果(值>=203&&value<249)
{
compassFault.text=[NSString stringWithFormat:@“%f°SE”,值];
}
否则如果(值>=249&&value<293)
{
compassFault.text=[NSString stringWithFormat:@“%f°W”,值];
}
否则如果(值>=293&&value<350)
{
compassFault.text=[NSString stringWithFormat:@“%f°NW”,值];
}
}

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