方法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:
--待续...