mathlatitude-longitudegeo

Calculate the center point of multiple latitude/longitude coordinate pairs


Given a set of latitude and longitude points, how can I calculate the latitude and longitude of the center point of that set (aka a point that would center a view on all points)?

EDIT: Python solution I've used:

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)

Solution

  • The simple approach of just averaging them has weird edge cases with angles when they wrap from 359' back to 0'.

    A much earlier question on SO asked about finding the average of a set of compass angles.

    An expansion of the approach recommended there for spherical coordinates would be: