【问题标题】:how to get angle using two latitude and longitude如何使用两个纬度和经度获得角度
【发布时间】:2014-12-02 10:42:40
【问题描述】:

我有一个应用程序,我想在其中执行一些自定义指南针功能假设我有位置 A 和位置 B 我标记了我的位置(位置 A)然后我移动了一段距离我的指南针应该指向位置 A 我可以移动的任何地方我正在引用 qiblacompass 功能,但当我移动到其他位置时它没有指向位置 A 这是我的代码

public static double getDirectionFromNorth(double degLatitude,
                double degLongitude) {


 final double direction_LATITUDE = Math.toRadians(angle_lat);
 double direction_LONGITUDE = Math.toRadians(angle_lng);

            double latitude2 = Math.toRadians(degLatitude);
            double longitude = Math.toRadians(degLongitude);

            double soorat = Math.sin(direction_LONGITUDE - longitude);
            double makhraj = Math.cos(latitude2) * Math.tan(direction_LATITUDE)
                    - Math.sin(latitude2) * Math.cos(direction_LONGITUDE - longitude);
            double returnValue = Math.toDegrees(Math.atan(soorat / makhraj));

            if (latitude2 > direction_LATITUDE) {
                if ((longitude > direction_LONGITUDE || longitude < (Math
                        .toRadians(-180d) + direction_LONGITUDE))
                        && (returnValue > 0 && returnValue <= 90)) {

                    returnValue += 180;

                } else if (!(longitude > direction_LONGITUDE || longitude < (Math
                        .toRadians(-180d) + direction_LONGITUDE))
                        && (returnValue > -90 && returnValue < 0)) {

                    returnValue += 180;

                }

            }
            if (latitude2 < direction_LATITUDE) {

                if ((longitude > direction_LONGITUDE || longitude < (Math
                        .toRadians(-180d) + direction_LONGITUDE))
                        && (returnValue > 0 && returnValue < 90)) {

                    returnValue += 180;

                }
                if (!(longitude > direction_LONGITUDE || longitude < (Math
                        .toRadians(-180d) + direction_LONGITUDE))
                        && (returnValue > -90 && returnValue <= 0)) {

                    returnValue += 180;
                }

            }
            // ***
            return returnValue;
        }

其中 angle_lat 和 angle_lng 是我的位置 纬度、经度和 degLatitude、degLongitude 是当我移动它时从我的 GPS 获取 lat、lng 的位置

请告诉我这段代码有什么问题,或者我有什么其他方法可以完成我的任务吗?

【问题讨论】:

  • 如果您希望您的指南针指向 locationA,那么 locationB 与这一切有什么关系?
  • locationB 是当我移动时,它会变长
  • 所以locationB就是罗盘的位置!?
  • 指南针应该指向LocationA

标签: android google-maps gps compass-geolocation google-geolocation


【解决方案1】:

使用此网页检查您的代码: http://www.movable-type.co.uk/scripts/latlong.html

那么当你知道你正确计算了两个纬度、经度之间的方向时 你会意识到这对于步行速度来说是不够的。

只需驾驶汽车或火车,以远高于 10 公里/小时的速度行驶,您的算法概率就会起作用。 要计算行人步行方向,您需要更高级的算法,考虑更多过去的位置,例如 30 米。

但是作为第一个镜头,为什么不简单地采用 Location 属性传递的方向: 它被称为航向或航向。拿那个来说,两个纬度/经度之间的方向更准确。 (因为 GPS 芯片内部,有更多信息可用)

【讨论】:

    猜你喜欢
    • 2012-03-29
    • 1970-01-01
    • 2011-07-06
    • 2011-08-18
    • 1970-01-01
    • 2019-10-11
    • 1970-01-01
    • 2017-01-01
    • 1970-01-01
    相关资源
    最近更新 更多