地图相关问题

1.获取两个点的航向角

public static double getAngle1(double latA, double lngA, double latB, double lngB) {
        double y = Math.sin(lngB - lngA) * Math.cos(latB);
        double x = Math.cos(latA) * Math.sin(latB) - Math.sin(latA) * Math.cos(latB) * Math.cos(lngB - lngA);
        double bearing = Math.atan2(y, x);
        bearing = Math.toDegrees(bearing);
        if (bearing < 0) {
            bearing = bearing + 360;
        }
        return bearing;
    }

2.获取两点的距离

 /**
     * 得到两点间距离
     * 返回单位是米
     */
    public static double getDistance(double longitude1, double latitude1,
                                     double longitude2, double latitude2) {
        double lat1 = rad(latitude1);
        double lat2 = rad(latitude2);
        double a = lat1 - lat2;
        double b = rad(longitude1) - rad(longitude2);
        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
                + Math.cos(lat1) * Math.cos(lat2)
                * Math.pow(Math.sin(b / 2), 2)));
        s = s * EARTH_RADIUS;
        s = Math.round(s * 10000) / 10000;
        TagUtils.aLog("两点间距离" + s);
        return s;
    }

    private static double rad(double d) {
        return d * Math.PI / 180.0;
    }

你可能感兴趣的:(地图相关问题)