我试图得到两个点,A 和 B,它们各自围绕中心点 C 水平和垂直距离各 5 公里。 因此,A 点和 B 点创建了一个边长为 10 公里的“盒子”,C 点位于该盒子的正中心。 这是我的代码:
//Distance is 5 kilometers
float distance = 5;
float latCenter = locationInfo.lastLat;
float lngCenter = locationInfo.lastLong;
// Calculate corner point distance in lat and long
float latDelta = distance/110.54f;
float longDelta = distance/(111.320f(float)Math.cos((double)latCenter));
// Calculate coordinates of the corner points
float latA = lat - latDelta;
float longA = lng - longDelta;
float latB = lat + latDelta;
float longB = lng + longDelta;
我知道这些是近似值,但在我的情况下,以 ~1km 的误差幅度进行近似就可以了。 垂直距离还好(10.06公里),但水平距离只有6公里左右,而不是10公里。
我的公式有什么问题吗?我猜这是一些非常简单的数学错误,但我就是找不到它。我需要一个非常简单快速的代码,所以我根据这个 StackOverflow 答案进行计算:Simple calculations for working with lat/lon + km distance?
最佳答案
我会赌度与弧度(来自 javadoc of cos ):
public static double cos(double a)
Returns the trigonometric cosine of an angle. Special cases: If the argument is NaN or an infinity, then the result is NaN. A result must be within 1 ulp of the correctly rounded result. Results must be semi-monotonic.
Parameters: a - an angle, in radians.
Returns: the cosine of the argument.
关于java - 在Java中计算纬度和经度坐标周围的 "box",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19302131/