複数の緯度/経度座標ペアの中心点を計算する 質問する

複数の緯度/経度座標ペアの中心点を計算する 質問する

緯度と経度の点のセットが与えられた場合、そのセットの中心点(つまり、すべての点のビューの中心となる点)の緯度と経度をどのように計算できますか?

編集: 私が使用した Python ソリューション:

Convert lat/lon (must be in radians) to Cartesian coordinates for each location.
X = cos(lat) * cos(lon)
Y = cos(lat) * sin(lon)
Z = sin(lat)

Compute average x, y and z coordinates.
x = (x1 + x2 + ... + xn) / n
y = (y1 + y2 + ... + yn) / n
z = (z1 + z2 + ... + zn) / n

Convert average x, y, z coordinate to latitude and longitude.
Lon = atan2(y, x)
Hyp = sqrt(x * x + y * y)
Lat = atan2(z, hyp)

ベストアンサー1

ありがとう!これはOPのソリューションのC#バージョンで、度数を使用しています。システム.デバイス.場所.地理座標クラス

public static GeoCoordinate GetCentralGeoCoordinate(
    IList<GeoCoordinate> geoCoordinates)
{
    if (geoCoordinates.Count == 1)
    {
        return geoCoordinates.Single();
    }

    double x = 0;
    double y = 0;
    double z = 0;

    foreach (var geoCoordinate in geoCoordinates)
    {
        var latitude = geoCoordinate.Latitude * Math.PI / 180;
        var longitude = geoCoordinate.Longitude * Math.PI / 180;

        x += Math.Cos(latitude) * Math.Cos(longitude);
        y += Math.Cos(latitude) * Math.Sin(longitude);
        z += Math.Sin(latitude);
    }

    var total = geoCoordinates.Count;

    x = x / total;
    y = y / total;
    z = z / total;

    var centralLongitude = Math.Atan2(y, x);
    var centralSquareRoot = Math.Sqrt(x * x + y * y);
    var centralLatitude = Math.Atan2(z, centralSquareRoot);

    return new GeoCoordinate(centralLatitude * 180 / Math.PI, centralLongitude * 180 / Math.PI);
}

おすすめ記事