Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better geodesy handling #2345

Merged
merged 16 commits into from
Jan 3, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use simpler distance formula (precision is good enough)
  • Loading branch information
mourner committed Jan 2, 2014
commit 9ce2cc5cbd5f05171e515ac95b4d57e45a8799a4
11 changes: 4 additions & 7 deletions src/geo/crs/CRS.Earth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ L.CRS.Earth = L.extend({}, L.CRS, {

R: 6378137,

// distane between two geographic points using Harvesine formula
// distane between two geographical points using spherical law of cosines approximation
distance: function (latlng1, latlng2) {
var rad = Math.PI / 180,
lat1 = latlng1.lat * rad,
lat2 = latlng2.lat * rad,
sin1 = Math.sin((lat2 - lat1) / 2),
sin2 = Math.sin((latlng2.lng - latlng1.lng) * rad / 2);
lat2 = latlng2.lat * rad;

var a = sin1 * sin1 + sin2 * sin2 * Math.cos(lat1) * Math.cos(lat2);

return this.R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return this.R * Math.acos(Math.sin(lat1) * Math.sin(lat2) +
Math.cos(lat1) * Math.cos(lat2) * Math.cos((latlng2.lng - latlng1.lng) * rad));
}
});