我想计算多个坐标(纬度/经度对)的确切中心。例如:
纽约:40.730610, -73.935242
芝加哥:41.881832, -87.623177
亚特兰大:33.753746, -84.386330
=>中心:lat, long
(可能在这里39, -82
附近)
您将如何使用Java实现此目标? 谢谢
答案 0 :(得分:0)
这可能有帮助
import java.util.ArrayList;
import java.util.List;
public class coordinate_check {
List<coordinate> places = new ArrayList<>();
public coordinate centre(){
if(places.size() == 1) return places.get(0);
final int size = places.size();
double x=0,y=0,z=0,lati,longi;
for(coordinate alpha : places){
lati = Math.toRadians(alpha.lat);
longi = Math.toRadians(alpha.lon);
double a = Math.cos(lati) * Math.cos(longi);
double b = Math.cos(lati) * Math.sin(longi);
double c = Math.sin(lati);
x+=a;
y+=b;
z+=c;
}
x/=size;
y/=size;
z/=size;
longi = Math.atan2(y,x);
double hyp = Math.sqrt(x*x+y*y);
lati = Math.atan2(z,hyp);
return new coordinate(Math.toDegrees(lati), Math.toDegrees(longi))
}
}
class coordinate{
static double lat;
static double lon;
public coordinate(double x, double y){
lat = x;
lon = y;
}
}
答案 1 :(得分:0)
正如已经回答的那样,请使用这些点创建一个多边形,然后从该多边形计算出calculateCentroid()