实际运用上,GPS搜星设备获取到的经纬度坐标多多少少都会出现漂移,依据具体的应用场景,原因各式各样。 比如在搜星芯片启动后的若干分钟和在楼宇密集的地方,是很容易出现的。解决漂移的办法也有多种。 一是,短时间内取多个点,根据点计算其平均值,是一个办法,另一个方法是采用聚合算法。这两种方法的前提都是在一定的时间内拿到一定数量的坐标点。
方法1验证:
/**
* WGS84坐标系
*/
private static Gps[] testpoint={
new Gps(40.0513118414,116.2975358963),
new Gps(40.0502770668,116.2980079651),
new Gps(40.0492299575,116.2985229492),
new Gps(40.0495420389,116.2995100021),
new Gps(40.0504988054,116.2990057468),
new Gps(40.0515458954,116.2984156609)
};
public class Gps {
private double wgLat;
private double wgLon;
public Gps(double wgLat, double wgLon) {
setWgLat(wgLat);
setWgLon(wgLon);
}
public double getWgLat() {
return wgLat;
}
public void setWgLat(double wgLat) {
this.wgLat = wgLat;
}
public double getWgLon() {
return wgLon;
}
public void setWgLon(double wgLon) {
this.wgLon = wgLon;
}
@Override
public String toString() {
return wgLat + "," + wgLon;
}
}
private static Gps GetCenterPoint(){
int total = testpoint.length;
System.out.println("size="+total);
double lat = 0, lon = 0;
for(Gps g: testpoint){
lat += g.getWgLat() * Math.PI / 180;
lon += g.getWgLon() * Math.PI / 180;
}
lat /= total;
lon /= total;
return new Gps(lat * 180 / Math.PI, lon * 180 / Math.PI);
}
public static void main(String[] args) {
Gps result = GetCenterPoint();
System.out.println("latlon="+result.getWgLat()+","+result.getWgLon());
}
结果:
广法2:
--待续...