如果POI落在阈值内,则计算GPS轴承

时间:2017-06-02 16:18:05

标签: android gps geometry geospatial

我正在做的用例是根据当前轴承在当前位置显示POI。例如,如果我要前往北方,我将不会显示来自南方的POI,而只会根据阈值内的方位显示POI。

Representation

Degrees

2 个答案:

答案 0 :(得分:1)

为避免360/0转换出现问题,您可以使用下一个条件计算周期

if (Cos(Bearing) * Cos(POI) + Sin(Bearing) * Sin(POI) > Cos(Threshold)) then
   POI direction lies in range Bearing +- Threshold

答案 1 :(得分:0)

这是我现在的解决方案。在努力简化它的同时。欢迎提出建议。

public static boolean isBearingWithinRange(double heading, double alertHeading, double threshold) {
    boolean status = false;
    double leftThresholdMin = heading - threshold;
    double leftThresholdMax = FULL_CIRCLE;
    double rightThresholdMin = 0.0d;
    double rightThresholdMax = 0.0d;

    double total = heading + threshold;

    if(total > FULL_CIRCLE) {
        rightThresholdMax = threshold - (FULL_CIRCLE - heading);

        if((alertHeading >= leftThresholdMin && alertHeading <= leftThresholdMax) ||
                (alertHeading >= rightThresholdMin && alertHeading <= rightThresholdMax)) {
            status =  true;
        }

    } else if(heading < threshold) {
        double diff =  (threshold - heading);
        leftThresholdMin = FULL_CIRCLE - diff;
        rightThresholdMax = threshold + heading;

        if((alertHeading >= leftThresholdMin && alertHeading <= leftThresholdMax) ||
        (alertHeading >= rightThresholdMin && alertHeading <= rightThresholdMax)) {
            status =  true;
        }

    } else {
        rightThresholdMax = heading + threshold;

        if(alertHeading >= leftThresholdMin && alertHeading <= rightThresholdMax) {
            status = true;
        }
    }
    return status;
}