I'm trying to fit a model using the gls() function to account for spatial autocorrelation. There are numerous examples of this, using something like corr = corSpher(form = ~lon + lat). The challenge however is that my data is fully global, such that I think I need to be calculating something like the Great Circle Distance or Haversine distance, rather than simply the Euclidean distance. The challenge is that coordinates with a longitude of -179 and +179 will incorrectly be assumed to be very far apart, unless I can model these as coordinates.
Is there are way to account for this in gls, or perhaps in a different R function?