I have a set of n geographical coordinates on the surface of Earth, for which I want to calculate a bounding box (find the easternmost, westernmost, northernmost and southernmost location) without falling back to user input (there's no UI to the program). The naive approach is "take max and min of latitude, max and min of longitude, done" - but this returns obviously suboptimal results when the set straddles the 180th meridian (see e.g. Fiji for a similar situation: https://www.openstreetmap.org/relation/571747#map=2/-16.6/0.0 should not zoom out to the whole planet, as the two halves are actually adjacent).
This is acknowledged in multiple solutions, e.g. in Algorithm for determining minimum bounding rectangle for collection of latitude/longitude coordinates , but not solved.
What didn't work:
- check how others do this (Leaflet has the same problem, see above)
- enumerate pitfalls (e.g. "if one of the cooordinates gets close to the 180th meridian") - won't work for points whose bounding box is across, but not close to the IDL (e.g. Japan and Hawaii)
- go through the coordinates and mark if 180 is crossed (depends on the ordering)

