Skip to content

Commit

Permalink
Merge pull request #4369 from Leaflet/use-mean-earth-radius
Browse files Browse the repository at this point in the history
Use mean earth radius for distance calculation in L.CRS.Earth.
  • Loading branch information
yohanboniface committed Apr 2, 2016
2 parents ec10c1b + 868c102 commit b7b409b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions spec/suites/geo/CRSSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,15 @@ describe("CRS.ZoomNotPowerOfTwo", function () {
});
});
});

describe("CRS.Earth", function () {
describe("#distance", function () {
// Test values from http://rosettacode.org/wiki/Haversine_formula,
// we assume using mean earth radius (https://en.wikipedia.org/wiki/Earth_radius#Mean_radius)
// is correct, since that's what International Union of Geodesy and Geophysics recommends,
// and that sounds serious.
var p1 = L.latLng(36.12, -86.67);
var p2 = L.latLng(33.94, -118.40);
expect(L.CRS.Earth.distance(p1, p2)).to.be.within(2886444.43, 2886444.45);
});
});
5 changes: 4 additions & 1 deletion src/geo/crs/CRS.Earth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
L.CRS.Earth = L.extend({}, L.CRS, {
wrapLng: [-180, 180],

R: 6378137,
// Mean Earth Radius, as recommended for use by
// the International Union of Geodesy and Geophysics,
// see http://rosettacode.org/wiki/Haversine_formula
R: 6371000,

// distance between two geographical points using spherical law of cosines approximation
distance: function (latlng1, latlng2) {
Expand Down

0 comments on commit b7b409b

Please sign in to comment.