两个经纬度坐标,计算角度

   /**
     * 计算两点之间的角度
     *
     * @param pntFirst
     * @param pntNext
     * @return
     */
    public double getAngle(LiveAngle pntFirst, LiveAngle pntNext) {
        double dRotateAngle = Math.atan2(Math.abs(pntFirst.x - pntNext.x), Math.abs(pntFirst.y - pntNext.y));
        if (pntNext.x >= pntFirst.x) {
            if (pntNext.y >= pntFirst.y) {
            } else {
                dRotateAngle = Math.PI - dRotateAngle;
            }
        } else {
            if (pntNext.y >= pntFirst.y) {
                dRotateAngle = 2 * Math.PI - dRotateAngle;
            } else {
                dRotateAngle = Math.PI + dRotateAngle;
            }
        }
        dRotateAngle = dRotateAngle * 180 / Math.PI;
        return dRotateAngle;
    }
public class LiveAngle {
    //包含两个字段,分别是x y坐标
    public double x;
    public double y;

    public LiveAngle(double x, double y) {
        this.x = x;
        this.y = y;
    }
}


你可能感兴趣的:(Android)