Calculate the center point of multiple latitude/longitude coordinate pairs

后端 未结 21 1580
暖寄归人
暖寄归人 2020-11-27 09:27

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 poi

21条回答
  •  悲哀的现实
    2020-11-27 09:43

    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:

    • Convert each lat/long pair into a unit-length 3D vector.
    • Sum each of those vectors
    • Normalise the resulting vector
    • Convert back to spherical coordinates

提交回复
热议问题