这里写自定义目录标题
java根据几个地点的经纬度,求出这些经纬度的中心点
最近项目中需要根据得到的一些地图上点的经纬度,求出这些经纬度的中心点的需求哦,为此写了一个方法。这里给大家分享一下。
public class CenterPoint {
/**
* 根据输入的地点坐标计算中心点
* @param str
* @return
*/
public static Map<String,Double> getCenterPoint(String str) {
String[] arr = str.split(";");
int total = arr.length;
double X = 0, Y = 0, Z = 0;
for(int i=0;i<arr.length;i++){
double lat, lon, x, y, z;
lon = Double.parseDouble(arr[i].split(",")[0]) * Math.PI / 180;
lat = Double.parseDouble(arr[i].split(",")[1]) * Math.PI / 180;
x = Math.cos(lat) * Math.cos(lon);
y = Math.cos(lat) * Math.sin(lon);
z = Math.sin(lat);
X += x;
Y += y;
Z += z;
}
X