tidwall / geojson

GeoJSON for Go. Used by Tile38
MIT License
130 stars 28 forks source link

Earth Radius #24

Closed patachi closed 1 year ago

patachi commented 1 year ago

I was playing around with Tile38 and noticed a little difference in the distance value. Tile38 uses 6371000m as earthRadius = 6371e3 geo.go#L12 Another one uses 6376500m GeoCoordinate.cs#L297

I don't know which one is more accurate.

Thanks for the awesome work.

tidwall commented 1 year ago

Neither are entirely accurate because earth is a wonky ellipsoid, and the haversine formula from the libraries you reference works on a sphere.

Both are probably close enough for general purpose though.

https://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html

Equatorial radius (km)          6378.137    
Polar radius (km)               6356.752         
Volumetric mean radius (km)     6371.000

If you need super accurate distances you might want to consider https://github.com/tidwall/geodesic. Albeit with much slower performance.

patachi commented 1 year ago

So in particular use cases, the distance should be calculated by a single formula on the whole app stack to achieve the same number everywhere.

thanks.