Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.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_Map - Fatal编程技术网

Iphone 如何获得两个点之间的角度?

Iphone 如何获得两个点之间的角度?,iphone,map,Iphone,Map,如何在iPhone地图应用程序上计算两个POI(兴趣点)坐标之间的角度(以度为单位)?我猜您会尝试计算两个兴趣点(POI)坐标之间的角度 计算a的弧: 另一种选择是假装您在笛卡尔坐标系上(速度更快,但在长距离上并非没有错误): 你在计算从一点到另一点的“方位”。这个网页上有一整套公式,还有很多其他地理量,比如距离和交叉轨迹误差: 这些公式有多种格式,因此您可以轻松地转换为iPhone所需的任何语言。还有javascript计算器,因此您可以测试您的代码,得到与他们相同的答案。如果其他解决方案不

如何在iPhone地图应用程序上计算两个POI(兴趣点)坐标之间的角度(以度为单位)?

我猜您会尝试计算两个兴趣点(POI)坐标之间的角度

计算a的弧:

另一种选择是假装您在笛卡尔坐标系上(速度更快,但在长距离上并非没有错误):


你在计算从一点到另一点的“方位”。这个网页上有一整套公式,还有很多其他地理量,比如距离和交叉轨迹误差:


这些公式有多种格式,因此您可以轻松地转换为iPhone所需的任何语言。还有javascript计算器,因此您可以测试您的代码,得到与他们相同的答案。

如果其他解决方案不适合您,请尝试以下方法:

- (int)getInitialBearingFrom:(CLLocation *)first
                        to:(CLLocation *)second
{
    float lat1 = [self degreesToRad:first.coordinate.latitude];
    float lat2 = [self degreesToRad:second.coordinate.latitude];
    float lon1 = [self degreesToRad:first.coordinate.longitude];
    float lon2 = [self degreesToRad:second.coordinate.longitude];
    float dLon = lon2 - lon1;
    float y = sin (dLon) * cos (lat2);
    float x1 = cos (lat1) * sin (lat2);
    float x2 = sin (lat1) * cos (lat2) * cos (dLon);
    float x = x1 - x2;
    float bearingRadRaw = atan2f (y, x);
    float bearingDegRaw = bearingRadRaw * 180 / M_PI;
    int bearing = ((int) bearingDegRaw + 360) % 360; // +- 180 deg to 360 deg

    return bearing;
}
对于最终轴承,只需从终点到起点取初始轴承,并将其反转(使用θ=(θ+180)%360)

您需要以下两个助手:

-(float)radToDegrees:(float)radians
{
    return radians * 180 / M_PI;
}
-(float)degreesToRad:(float)degrees
{
    return degrees * M_PI /180;
}

什么是POI,什么是“iPhone amp应用程序”@Radek S:在@Jano更新了原始问题后,这应该是有意义的。的确,Jano的东西在这里不起作用,但你提到的网站确实帮了大忙。但是请注意:他们忘记了在Javascript的轴承示例中,lat/long必须采用辐射格式。GreatCircle不会将输入转换为弧度。要将输入转换为弧度吗
#define RADIANS_TO_DEGREES(radians) ((radians) * 180.0 / M_PI)
- (int)getInitialBearingFrom:(CLLocation *)first
                        to:(CLLocation *)second
{
    float lat1 = [self degreesToRad:first.coordinate.latitude];
    float lat2 = [self degreesToRad:second.coordinate.latitude];
    float lon1 = [self degreesToRad:first.coordinate.longitude];
    float lon2 = [self degreesToRad:second.coordinate.longitude];
    float dLon = lon2 - lon1;
    float y = sin (dLon) * cos (lat2);
    float x1 = cos (lat1) * sin (lat2);
    float x2 = sin (lat1) * cos (lat2) * cos (dLon);
    float x = x1 - x2;
    float bearingRadRaw = atan2f (y, x);
    float bearingDegRaw = bearingRadRaw * 180 / M_PI;
    int bearing = ((int) bearingDegRaw + 360) % 360; // +- 180 deg to 360 deg

    return bearing;
}
-(float)radToDegrees:(float)radians
{
    return radians * 180 / M_PI;
}
-(float)degreesToRad:(float)degrees
{
    return degrees * M_PI /180;
}