计算两个经纬度间的距离

private final static double PI = 3.14159265358979323; // 圆周率
private final static double R = 6371229; // 地球的半径

//(x,y) (dianx,siany)
double x,y,dianx,siany; Double xx,yy,distance = 0.0; xx = (x - dianx) * PI * R * Math.cos(((y + siany) / 2) * PI / 180) / 180;
yy
= (y - siany) * PI * R / 180; distance = Math.hypot(xx, yy); int juli=(int) ((distance*10)/10); System.out.println("两地距离"+distance);