根据坐标数组计算中心点

/// <summary>
/// 计算地图中心点
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
private string GetCenterByList(List<BmapPo> list)
{
var result = string.Empty;
var total = list.Count;
double X = 0;
double Y = 0;
double Z = 0;

foreach (BmapPo po in list)
{
var lng = Convert.ToDouble(po.x)*Math.PI/180;
var lat = Convert.ToDouble(po.y)*Math.PI/180;
double x, y, z;
x = Math.Cos(lat)*Math.Cos(lng);
y = Math.Cos(lat)*Math.Sin(lng);
z = Math.Sin(lat);
X += x;
Y += y;
Z += z;
}
X = X/total;
Y = Y/total;
Z = Z/total;

var Lng = Math.Atan2(Y, X);
var Hyp = Math.Sqrt(X*X + Y*Y);
var Lat = Math.Atan2(Z, Hyp);
result = Lng*180/Math.PI + "," + Lat*180/Math.PI;
return result;
}

 

传入坐标数组  输出以逗号分隔的中心点经纬度

posted @ 2016-05-26 16:35  Loser0628  阅读(1148)  评论(0编辑  收藏  举报