如何使用Java测试一个点是否在具有纬度/经度和半径的区域内?
我必须编写一个具有以下签名的方法
public class Position {
double longitude;
double latitude;
}
boolean isInsideTheArea(Position center, double radius, Position point);
因此,如果 point
位于以 center
为中心且 area
内>radius 作为其以英里为单位的半径,这应该返回true
,否则返回false
。
I've to write a method that has the following signature
public class Position {
double longitude;
double latitude;
}
boolean isInsideTheArea(Position center, double radius, Position point);
So if point
is inside the area
that has the center
as its center and radius
as its radius in miles, this should return true
, false
otherwise.
使用半正矢公式计算
中心
和点
之间的距离。如果该距离大于radius
,则返回false
;否则返回true
。伪代码:
Use the Haversine formula to compute the distance between
center
andpoint
. If that distance is greater thanradius
, returnfalse
; otherwise returntrue
.Pseudocode: