# 地图算法（四）：判断当前点是不是在圆内

``````public class CircleAreaJudge {
private double cx = 0.0D;
private double cy = 0.0D;
private double r = 0.0D;

public CircleAreaJudge(double x, double y, double r) {
try {
this.cx = x;
this.cy = y;
this.r = r;
} catch (NumberFormatException localNumberFormatException) {
}
}

public boolean isInArea(double x, double y) {
return isInArea(x, y);
}

public boolean isInArea(String x, String y) {
double dis = RuleUtil.computeLength(Double.parseDouble(x), Double.parseDouble(y), this.cx, this.cy);
if (dis < this.r) {
return true;
}
return false;
}

public static void main(String[] args) {
CircleAreaJudge circleAreaJudge=new CircleAreaJudge(2.0, 2.0, 1);
System.out.println(circleAreaJudge.isInArea("1","1"));
}
}``````

RuleUtil.computeLength

``````    public static double computeLength(double dwStartX, double dwStartY, double dwEndX, double dwEndY) {
double PI = 3.1415926535898D;

double latRadians1 = dwStartY * (PI / 180.0D);
double latRadians2 = dwEndY * (PI / 180.0D);
double latRadians = latRadians1 - latRadians2;
double lngRadians = dwStartX * (PI / 180.0D) - dwEndX * (PI / 180.0D);
double f = 2.0D * Math.asin(Math.sqrt(Math.pow(Math.sin(latRadians / 2.0D), 2.0D)
+ Math.cos(latRadians1) * Math.cos(latRadians2) * Math.pow(Math.sin(lngRadians / 2.0D), 2.0D)));
return f * 6378137.0D;
}``````