Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var Distance = {
rad: function (x) {
return x * Math.PI / 180;
},
haversine: function (p1, p2) {
var R = 637100000,
dLat = this.rad(p2.latitude - p1.latitude),
dLong = this.rad(p2.longitude - p1.longitude),
a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(this.rad(p1.latitude)) * Math.cos(this.rad(p2.latitude)) * Math.sin(dLong / 2) * Math.sin(dLong / 2),
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)),
d = R * c;
return Math.round(d);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.