如何使用Java测试一个点是否在以纬度/经度和半径表示的区域内?

3
我需要编写一个具有以下签名的方法:
public class Position {
double longitude;
double latitude;
}

boolean isInsideTheArea(Position center, double radius, Position point);

如果point在以center为中心,radius为半径的区域内,那么应该返回true,否则返回false。单位为英里


实际上,我在这个领域没有经验。但是我知道应该使用Haversine公式。 - mohamede1945
2个回答

7

使用 Haversine 公式 计算 centerpoint 之间的距离。如果该距离大于 radius,则返回 false;否则返回 true

伪代码:

def haversineDistance(a, b):
    # snip...
    return foo

def isInsideTheArea (center, radius, point):
    return haversineDistance(center, point) <= radius

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接