Triangulating GPS coordinates

geometrygpsmath

Say you have n GPS coordinates how could you work out the central GPS point between them?

Best Solution

In case it helps anyone now or in the future, here's an algorithm that's valid even for points near the poles (if it's valid at all, i.e. if I haven't made a silly math mistake ;-):

  1. Convert the latitude/longitude coordinates to 3D Cartesian coordinates:

    x = cos(lat) * cos(lon)
    y = cos(lat) * sin(lon)
    z = sin(lat)
    
  2. Compute the average of x, the average of y, and the average of z:

    x_avg = sum(x) / count(x)
    y_avg = sum(y) / count(y)
    z_avg = sum(z) / count(z)
    
  3. Convert that direction back to latitude and longitude:

    lat_avg = arctan(z_avg / sqrt(x_avg ** 2 + y_avg ** 2))
    lon_avg = arctan(y_avg / x_avg)