您的位置:首页 > 编程语言 > Java开发

计算 GPS 经纬度 两点间 距离 JAVA 代码

2012-04-28 10:14 661 查看
原文转自:http://blog.csdn.net/xjanker2/article/details/5404487
public class FCDTools {

public final static double PI 	= 3.14159265354;
private final static double D2R 	= 0.017453 ;
private final static double a2 	= 6378137.0;
private final static double e2 	= 0.006739496742337;

public static double Distance(FCD_Point pt1, FCD_Point pt2) {
if(pt1.lng == pt2.lng && pt1.lat == pt2.lat ) {
return 0.0;
} else {
double fdLambda =(pt1.lng - pt2.lng) * D2R;
double fdPhi = (pt1.lat - pt2.lat) * D2R;
double fPhimean = ((pt1.lat + pt2.lat) / 2.0) * D2R;
double fTemp = 1 - e2 * (Math.pow (Math.sin(fPhimean),2));
double fRho = (a2 * (1 - e2)) / Math.pow (fTemp, 1.5);
double fNu = a2 / (Math.sqrt(1 - e2 * (Math.sin(fPhimean) * Math.sin(fPhimean))));
double fz = Math.sqrt (Math.pow(Math.sin(fdPhi / 2.0), 2) +
Math.cos(pt2.lat * D2R) * Math.cos( pt1.lat*D2R ) * Math.pow( Math.sin(fdLambda / 2.0),2));
fz = 2 * Math.asin(fz);
double fAlpha = Math.cos(pt2.lat * D2R) * Math.sin(fdLambda) * 1 / Math.sin(fz);
fAlpha = Math.asin (fAlpha);
double fR = (fRho * fNu) / ((fRho * Math.pow( Math.sin(fAlpha),2)) + (fNu * Math.pow( Math.cos(fAlpha),2)));
return fz * fR;
}
}
}


测试:

System.out.println(FCDTools.Distance(new FCD_Point(117.107277,31.980298),
new FCD_Point(117.524757, 31.888227)));
// 输出40.7公里
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java distance class 测试