本文根据《GPS经纬度坐标转平面坐标的简化计算方法及精度分析》这篇文章中的的方法将GPS经纬度坐标转换为以地平面上平面直角坐标系中的X、Y坐标。这个转换方法的前提是在一定的范围以内。具体的转化公式请参考该文,下面是坐标转换的代码:
public class PlaneCoordinate {
/**
* 平面坐标系
*/
private static final double MACRO_AXIS = 6378137; // 赤道圆的平均半径
private static final double MINOR_AXIS = 6356752; // 半短轴的长度,地球两极距离的一半
// 返回Y坐标
private static double turnY(GePoint basePoint, GePoint point) {
double a = Math.pow(MACRO_AXIS, 2.0);
double b = Math.pow(MINOR_AXIS, 2.0);
double c = Math.pow(Math.tan(basePoint.getLatitude()), 2.0);
double d = Math.pow(1/Math.tan(basePoint.getLatitude()),2.0);
double x = a/Math.sqrt(a + b*c);
double y = b/Math.sqrt(b + a*d);
c = Math.pow(Math.tan(point.getLatitude()), 2.0);
d = Math.pow(1/Math.tan(point.getLatitude()), 2.0);
double m = a/Math.sqrt(a + b*c);
double n = b/Math.sqrt(b + a*d);
return new PePoint(x, y).distanceBetween(new PePoint(m, n));
}
// 返回X坐标
private static double turnX(GePoint basePoint, GePoint point) {
double a = Math.pow(MACRO_AXIS, 2.0);
double b = Math.pow(MINOR_AXIS, 2.0);
double c = Math.pow(Math.tan(basePoint.getLatitude()), 2.0);
double x = a/Math.sqrt(a + b*c);
return x * (point.getLongtitude() - basePoint.getLongtitude());
}
}
/* 经纬度坐标点(84坐标系) */
public class GePoint {
private double latitude; // 纬度坐标
private double longtitude; // 经度坐标
public GePoint() {
}
public GePoint(double latitude, double longtitude) {
this.latitude = latitude;
this.longtitude = longtitude;
}
public double getLatitude() {
return 2 * latitude * Math.PI / 360 ;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongtitude() {
return 2 * longtitude * Math.PI / 360;
}
public void setLongtitude(double longtitude) {
this.longtitude = longtitude;
}
}