【问题标题】:Find location 1 Km away in 180 degree (South) from my location查找距我的位置 180 度(南)1 公里外的位置
【发布时间】:2016-05-20 13:38:20
【问题描述】:

我有一个位置(纬度和经度),我想找到下一个位置(纬度和经度),它距我的位置(经度和纬度)180 度角(向南)1 公里。能给我和算法或函数吗?

【问题讨论】:

标签: java android geolocation location


【解决方案1】:

从 Java 中的 Rosetta code 实现开始:

public static double haversine(double lat1, double lon1, double lat2, double lon2) {
    double dLat = Math.toRadians(lat2 - lat1);
    double dLon = Math.toRadians(lon2 - lon1);
    lat1 = Math.toRadians(lat1);
    lat2 = Math.toRadians(lat2);

    double a = Math.pow(Math.sin(dLat / 2),2) + Math.pow(Math.sin(dLon / 2),2) * Math.cos(lat1) * Math.cos(lat2);
    double c = 2 * Math.asin(Math.sqrt(a));
    return R * c;
}

如果你知道lon1 == lon2,那么这段代码中的大量代码会直接丢失,因为dLon == 0

public static double haversine(double lat1, double lat2) {
    double dLat = Math.toRadians(lat2 - lat1);
    return R * dLat;
}

(应该熟悉为length = Radius * angle in radians 公式)

所以,如果您知道R = 6372.8,并且您想要的结果是1,那么很容易为dLat 提供一个值:

dLat = 1.0 / 6372.8;

换句话说,只需从您当前的纬度中减去1.0 / 6372.8(并记住小心处理小于180 - 1.0 / 6372.8 的纬度点)。

【讨论】:

    【解决方案2】:

    查看SimpleLatLng 库及其travel() 方法的简单解决方案:

    /**
         * <p>
         * Calculate the end point of traveling along a great-circle path from a
         * given starting point with a given intitial bearing for a known distance.
         * </p>
         * 
         * @param start
         *            the starting point.
         * @param initialBearing
         *            the initial bearing.
         * @param distance
         *            the distance to travel.
         * @param unit
         *            the unit in which distance is measured.
         * @return the end point.
         */
        public static LatLng travel(LatLng start, double initialBearing, double distance,
                LengthUnit unit) {
            double bR = Math.toRadians(initialBearing);
            double lat1R = Math.toRadians(start.getLatitude());
            double lon1R = Math.toRadians(start.getLongitude());
            double dR = distance / LatLngConfig.getEarthRadius(unit);
    
            double a = Math.sin(dR) * Math.cos(lat1R);
            double lat2 = Math.asin(Math.sin(lat1R) * Math.cos(dR) + a * Math.cos(bR));
            double lon2 = lon1R
                    + Math.atan2(Math.sin(bR) * a, Math.cos(dR) - Math.sin(lat1R) * Math.sin(lat2));
            return new LatLng(Math.toDegrees(lat2), Math.toDegrees(lon2));
        }
    

    您只需为其指定起点、方向、距离和单位,即可获得计算出的位置。您需要获取完整的库,因为此方法使用库声明的一些类。它还有一些其他有用的计算。

    它在Apache 2.0 License 下可用。

    【讨论】:

      【解决方案3】:

      向南移动,也向北移动,使计算变得简单,因为它避免使用经度。 See

      1 公里等于 0.0088339 度。

      所以在北半球,从位置的纬度中减去 0.0088339 并保持经度不变。 对于南半球,添加 0.0088339。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-07-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-14
        • 2021-06-27
        • 2018-08-13
        • 2021-07-06
        相关资源
        最近更新 更多